Cycles Cuda out of memory on final render but not on preview
The difference and reason why it renders in previw and not in render is this setting:



In render the surface gets divided a lot more, so the geometry takes a lot of VRAM. Your scene takes 4.2 GB of it in render.

Also many other modifiers have separate settings for viewport/render, there may be objects hidden from preview etc.

Try to lower the quality till it fits in memory, or render on CPU or borrow/buy better GPU.