Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Possible memory leak during recursion

 
Thai C. Tran
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • 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]
 
Emanuel Kadziela
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic