• 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:

can the cause of memory leak be detected here?

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello all,
I've been facing an outofmemory error for a quite a long time now and since I'm also new to Java, I have been unsuccessful in tracing the leak.
I have herewith posted the code that has been giving me the problems.
It sure is a longg code..Can you please patiently go through the code to point me out where the references have not been released, or what other mistakes have been done and thereby guide me with it?
Sorry for the trouble and thanks a million in advance.

SnmpRequest.java
----------------



SnmpThread.java
---------------



Thanks for your time and waiting for a reply.
Regards
aparna
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The best way I know to find a memory leak is to run the code in a profiler which can show the number of instances for each class. Search for classes whichs number of instances increases in unsuspected dimensions.

A good profiler than can also tell you why those instances aren't garbage collected.
 
Aparna Ram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Could you then suggest such a profiler which would help me find out why the instances are not getting garbage collected?
I use:
Netbeans 4.1 IDE
jdk_1.4.2
Tomcat 5.0

kindly guide.
TIA
Regards
Aparna
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We are using JProfiler at work. It's quite good, but not free.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had a memory leak one time due to objects extending Thread being created but not allowed to run. I thought the objects would be GCed because I dropped the reference but it turns out that all objects extending Thread get registered in a ThreadGroup held by the JVM.
I finally detected this by adding a method that would get the ThreadGroup and dump a list of all the held Threads - boy was I surprised

Bill
 
Aparna Ram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for your reply. I now check the number of active threads, it keeps on increasing at a whopping rate.!
Is this causing teh memory leak? How do I proceed now?
How were you able to solve your problem of memory leak?

Kindly guide me through.

Thanks and Regards
Aparna
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Endlessly increasing number of active Threads can certainly cause a memory leak - it did for me!
My solution was to rewrite the code so that every Thread gets start()ed - but a simple flag is checked in the run method to immediately return ; if the run conditions are not met. The JVM Thread management will take care of disposing of the object extending Thread - assuming you keep no other reference to it - but you have to exit the run() method.
Please let us know how it turns out!
Bill
reply
    Bookmark Topic Watch Topic
  • New Topic