• 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
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Possible memory leak during recursion

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have recursion function, which access to the database through hibernate 3 in order to count all the members of a directory. Here is the code of the function



And here is the code for DirectoryEntity implementation


And for the findbyId function



everytime the function is finished, the memory is increased significantly and objects in the heap is not garbage collected. I tried to use MAT to use analyse the problem (please see the attachement). It looks like I have a issue with opening/closing transation but still have no idea how to fix it. Can anyone have any suggestion, please? Please ask more code if necessary
MAT.PNG
[Thumbnail for MAT.PNG]
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are indeed not closing transactions, then you didn't post enough information. How is hibernate setup? What is the reference to "dao" in this line: "dao.getSession().get(ReflectionUtils.getSuperClassGenricType(getClass()), id);" pointing to? What "dao"? How does that "dao" implement "getSession()"?
 
Thai C. Tran
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I didn't make the question clear. As the title said, it is possible to leak; but actually, it is not . I have checked all the connection handling and cannot find anything wrong with it. After using yourkit tool (it allows to check the heap space continuously with the force GC running function), it turned out that because we are using thread in order to run that function, the heap space keeps increasing so fast but the GC cannot run fast enough to free the unused memory. So, what I did is trying to clear the session when possible (after each thread) and the most important thing is using this suggestion. The test case passed even with the 64 MB.

Thank for your time
reply
    Bookmark Topic Watch Topic
  • New Topic