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
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
Joined: Jul 05, 2009
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.