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

Finding Memory Leaks

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, I have a huge program that after 4 hours or so of executing, crashes because of a 'out of memory' error.
I have downloaded jprobe and optimizeit, but do not know how to fully utilize the information from these windows. Anybody else use these programs before?
Anybody have any suggestions on how to fix a memory leak?
Thanks
 
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have not used the tools you metioned. But from my MSWindows experiences and understanding of Java. I've some suggestions on how to avoid and fix mem-leaks.
1) Recycle huge objects, do your own mem-management. Pooling is one way to do it. Using an arrays to recycle them is another simple way, create new one only when the recycling array is empty. I used to do this in c around the x286 time.
2) When an object is not in use any more, explicitly set it to null. But this will depend on the concious of your programmers.
3) When you use tools (like JProbe or the BoundsChecker in the old days). Find the area which uses memory most, and refactor (redesign/code) that part.

SCJD Study Group has been moved to http://www.developergroup.org/
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another thing I'd like to point out is:
Unlike C++, programmers are responsible to deallocate the memory. If programmer forget to do that, the tools detect the mem-leak and report it. The job is easier for the tools.
In java, programmers usually think the GC is responsible to deallocate the memory. Officially, Java should not have mem-leak. However, it is far from the truth. Java mem-leak is actually unintentional retain of object references, which means the object is no longer needed, but still be referred somewhere. This kind of mem-leak is much harder to detect.
Read here, it is the CTO of your tool: http://industry.java.sun.com/javaone/99/event/0,1768,618,00.html
 
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic