Hibernate version: 3.0.5
Hi everybody!
Consider the following model:
Code:
class A {
B b; // B is mapped with many-to-one association.
public void getB() {
}
}
class B {
...
public void foo() {
}
...
}
After loading object A with Session.load method, I'm calling B's foo() method:
Code:
a.getB().foo()
After doing that, object B (and A) are
never released -
even after transaction is ended. I think this is a wrong behavior which causes a memory leak.
I think that the reason is:
This scenario causes CGLIBLazyInitializer to load object B and to store it in its "target" data member. As I understand, CGLIBLazyInitializer is registered as some kind of "callback" in the CGLib framework. CGLib framework stores an array of those "callbacks" in the ThreadLocal variable.
The trouble is: I'm working with Tomcat. I'm opening (an closing) transaction for every request to the Web Server. But Tomcat reuses its threads, so ThreadLocals live
beyond the transactional scope and those object B will live after the transaction is ended.
Am I doing something wrong? Or is it a bug?? I have rechecked it several times with a profiler.
Thanks a lot!
Michael.