• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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: 76433
366
  • 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.
 
Nothing up my sleeve ... and ... presto! A tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic