jQuery in Action, 2nd edition
The moose likes Java in General and the fly likes Regarding Memory Leaks Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Regarding Memory Leaks" Watch "Regarding Memory Leaks" New topic
Author

Regarding Memory Leaks

sarma kiran
Ranch Hand

Joined: Jul 17, 2008
Posts: 30
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..
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32833
    
    4
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding Memory Leaks
 
Similar Threads
Memory leaks
Threads
Garbage collection
Out of Memory
life cycle in different scopes