• Post Reply Bookmark Topic Watch Topic
  • New Topic

Out of memory recovery  RSS feed

 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have received the out of memory error. The code below simulates the memory error, and the notional fix. To see the error, set recoverMemory to false, to see the proposed fix, set recoverMemory to true. Does the proposed fix implement a proper method to recover memory?

 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think there is any reliable method for recovery from an out of memory error.

What would "recovery" mean anyway, you have no idea what condition all of the variables in the program are left in.

Bill
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William Brogden wrote:I don't think there is any reliable method for recovery from an out of memory error.

What would "recovery" mean anyway, you have no idea what condition all of the variables in the program are left in.


Also, the technique used in the example isn't very functional. So, basically, the recovery technique is simply to toss the data? Really? The data is not important that it can be disposed of? And if this is true, why didn't the application dispose of it in the first place? Why does it have to wait for an out-of-memory condition to dispose of it? Data is held by the application for a reason, and there aren't many scenarios, where an application can simply toss stuff and expect to keep running.

The only obvious scenario that I can think of is a cache -- meaning data that is loaded is kept around for speed of operations purposes, but it can be disposed of at anytime. Disposing the data is basically sacrificing the speed for memory needs. However, for this scenario, there is a better technique. The cache should be held with soft references only. When the data is needed, the cache is searched, and a hard reference to the data is provided to the executing program. While data is in the cache, and not used, only soft references exist -- and with soft references, the garbage collector will try it best to not collect it. But, if it is pressed for memory, it will collect the memory, and the next time the cache is searched, the application will find a soft reference to null.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!