• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding GarbageCollection and OOM problem  RSS feed

 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anybody please tell me as why doesn't a garbage collection guarantee that a program will not run out of memory?
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi RaviNada,

this answer is easy. Only objects which aren't used (i.e. strong referenced) any more by an application can be garbage collected. It's obvious that the GC can't simply destroy and remove objects from memory which are still in use by a program. So you have to take care to hold references to objects only as long as needed an especially to prevent memory leaks. Of course the whole process of memory management depends also on the overall memory requirements of an application and the amount of memory which is available to the machine or JVM which runs the application. In the simplest case a machine just doesn't have enough memory for the needs of a specific application. Then it should be clear that no garbage collector can avoid that the program runs out of memory.

Marco
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes eexactly ,

Thanks Marco for your excellent explanation.
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome ;-)

I hope my explanation was helpful for you! But keep in mind that garbage collection in modern JVMs is much more complex than it may seem from my answer. In particular they do not simply differentiate between used and unused objects. If you are interested then you may check out the following articles:

Tuning garbage collection
Garbage collection and performance

They explain in more detail what a garbage collector is doing!


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