I’m using an API that provides a method like remoteConnection.getObjects() to get a list of objects from a remote server. The list is sometimes huge and causes a Java heap space OutOfMemoryError. Is there a way of dumping these objects directly to a file rather than have them loaded in memory?
I’m using an API that provides a method like remoteConnection.getObjects() to get a list
Share
From what you have described, unfortunately the answer is no you cant – “Out of Memory” doesn’t actually mean that you have run out of physical memory, it means that your virtual address space is too full / fragmented to allocate any more.
In short – paging bits of memory to disk won’t help you because physical memory isn’t the bottleneck, the limiting factor is simply the ability to address memory. (The OS will already be seamlessly paging memory to disk for you).
Your options (that I can see) are: