Menu

#2 fixes memory leak when cglib is loaded by WebappClassLoader

open
nobody
None
5
2005-10-14
2005-10-14
Donald Ball
No

I've got a hibernate webapp which was leaking memory
when reloaded. After reading the lengthy discussion here:

http://forum.hibernate.org/viewtopic.php?t=935948

and here:

http://opensource2.atlassian.com/confluence/spring/pages/viewpage.action?pageId=2669

I identifed two class fields in ReflectionUtils that
are definitely keeping WebappClassLoader from being
garbage collected on my system (vanilla versions of sun
jdk-1.4.2_08 on winxp, tomcat-5.0.28). After applying
the attached patch to cglib (switching from static
fields to static methods for the offenders), I can
reload my webapp without having to resort to the tricks
I note at the bottom of the hibernate thread.

The tests pass and cglib does not seem any slower. I
agree with Christian that these static fields oughtn't
inhibit garbage collection, but the fact of the matter
is that this patch definitely solves the problem for me.

Any chance of inclusion? More importantly, can y'all
explain why this patch works? :)

Discussion

  • Donald Ball

    Donald Ball - 2005-10-14

    context diff against cvs 2005-10-14

     
  • Juozas Baliuka

    Juozas Baliuka - 2005-10-17

    Logged In: YES
    user_id=337001

    It is valid to reference self classloader (GC solves it).
    Probably you patched cglib from CVS head and probably the
    latest version doe's not leak classloader with or without this
    patch (there are some fixes related to class loader leak
    problem).