• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Garbage Collection

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
This is a line from K&B book

"About the only thing you can guarantee is that if you
are running very low on memory, the garbage collector will run before it throws an OutOfMemoryException."

So a java program never throws an OutOfMemoryException. Is this correct ?

Thanks

Gayatri
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's not quite true.
The guarantee that is made is that there will be no objects available for garbage collection at the time an OOME is thrown. I'll find the spec. reference next Tuesday for you
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just think about the case that the program keeps creating objects with non-null value inside an infinite loop, it finally caused OutOfMemoryException as there is NO de-referenced objects to be collected.

Nick
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a point to note, java.lang.OutOfMemoryError implies a VM fatal condition, however, the VM is not actually of memory - only an allocation failed.
Consider the following. The VM has 2 bytes of memory remaining, an attempt to allocate 3 bytes is made and it fails with a OOME, however, the application could otherwise continue running normally. This is not a fatal condition.
 
reply
    Bookmark Topic Watch Topic
  • New Topic