This question already has an answer here:
If I copy text into the xterm clipboard (
"+y) from gvim, it is cleared when I exit gvim.
How do I prevent this?
I've found the solution for vim, but it doesn't work for Gvim:
autocmd VimLeave * call system("echo -n $'" . escape(getreg(), "'") . "' | xsel -ib")