• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding Memory Leaks

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Am going through the Memory Leaks Concept.

I have come across the below line.

"In Java typically memory leak occurs when an object of longer life cycle has a reference to objects of a short life
cycle."

Can any one explain with some example?

Thanks in advance..
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Imagine you have a stack, implemented on an array. You can push objects onto the stack by sayingThen you pop things off the stack like thisThen you forget all about the f reference. But you have forgotten that it is still on that array. If you don't push anything else onto the stack, that f reference will stay there for ever. You have no methods allowing access to it, but the JVM still sees it as "reachable." If you find a copy of Joshua Bloch's Effective Java look on page 24 (2nd edition; don't know page for 1st edition) and it gives a much better explanation of the same problem.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic