|
From: Guillaume P. <gpo...@gl...> - 2004-10-23 03:43:51
|
Andy=2C What you are seeing there is a symptom=2C not the cause of your leak=2E = What cause the leak is that the ClassLoader is never collected=2C in whic= h case the CachedIntrospectionResults are of little effect in comparaison= to the memory taken by every classes and their static members=2E If you= r ClassLoader is not collected=2C you might even have external resources = not freed=2C such as JDBC Connections=2C if you have a reference from a s= tatic member to your connection pool (directly or indirectly)=2E Any servlet container will release the ClassLoader when the webapp is unl= oaded=2C but there=27s many things (bugs) that might prevent the ClassLoa= der to be collected=2E The most probable causes I was personally able to= identify are the cache in java=2Elang=2EIntrospector=2C a Driver left u= nregistered in DriverManager or ThreadLocal variable not cleared=2E But = in any case=2C unless there was a bug in the patch I provided=2C or that = it somehow got broken since (in both cases I doubt it)=2C then code in Ca= cheIntrospectionResults will never prevent the ClassLoader to be garbage = collected=2E So=2C most likely=2C it=27s not a JBoss problem=2C nor a Spring problem=2C= but a problem in your own code or in libraries such as DOM4J=2E For the Introspector=2C the solution (beside not using it)=2C is to have = a ContextListener that call Introspector=2EflushCaches() when the context= is destroyed=2E Spring provide one=2C it=27s os=2Eweb=2Eutil=2EIntrospe= ctorCleanupContextListener or something like that=2E Also=2C the leak in = the Introspector is only an issue for JDK up to JDK 1=2E4=2E2=2C the prob= lem was corrected in 1=2E5=2E For the a Driver that wasn=27t unregistered (if your driver class is in W= EB-INF/lib)=2C the solution is similar=2C you need to have a ContextListe= ner=2C when the context is destroyed=2C you ask for a list of the registe= red Drivers from DriverManager=2C and you remove any that comes from your= webapp (you can check its ClassLoader)=2E For the ThreadLocal stuff=2C you have to make sure anything you put in th= ere you eventually remove it=2E But if a third party libary does that (e= =2Eg=2E DOM4J) can you can=27t fix it or have it fixed=2C then it=27s mor= e complicated to solve=2E You can look in a previous email from me to th= is list for a pontential workaround=2C but it=27s kind of a hack=2C and w= ould be dangerous in production because of concurrency issues=2E Guillaume ---- Messages d=B4origine ---- De=3A Andy Depue =3Candy=40marathon-man=2Ecom=3E Date=3A vendredi=2C octobre 22=2C 2004 6=3A25 pm Objet=3A =5BSpringframework-developer=5D CachedIntrospectionResults leak=3F= =3E I know this comes up every now and again=2C but I have a leak = =3E related to Spring=2E = =3E I=27m using the latest version of Spring=2C and it appears that = =3E org=2Espringframework=2Ebeans=2ECachedIntrospectionResults is the = =3E culprit=2E = =3E CachedIntrospectionResults does not use WeakReferences for values = =3E in the = =3E =22classCache=22 static WeakHashMap when placing Classes that have = =3E been loaded = =3E through the same class loader as the CachedIntrospectionResults=2E = =3E I guess it = =3E assumes that the ClassLoader of the CachedIntrospectionResults = =3E will be = =3E garbage collected when the container unloads the app=3F However=2C i= n = =3E my case = =3E this is not happening=2C and the leaked CachedIntrospectionResults = =3E instances = =3E are eating up memory=2E JBoss 4=2E0 doesn=27t seem to release the Cl= ass = =3E (though I = =3E haven=27t figured out why yet=2E=2E=2E OptimizeIt doesn=27t want to s= how me = =3E who is = =3E holding the reference to the Class itself)=2E In fact=2C I=27ve noti= ced = =3E that = =3E generally static references (such as =22classCache=22) are not = =3E released when = =3E JBoss 4=2E0 unloads an application=2E Not being any kind of expert o= n = =3E class = =3E loading=2C especially how JBoss does class loading=2C does anyone kno= w = =3E what the = =3E right solution to this issue would be=3F Is this a JBoss problem=3F = = =3E Is it a = =3E Spring problem=3F =3E = =3E Thanks=2C =3E Andy =3E = =3E = =3E ------------------------------------------------------- =3E This SF=2Enet email is sponsored by=3A IT Product Guide on = =3E ITManagersJournalUse IT products in your business=3F Tell us what = =3E you think of them=2E Give us =3E Your Opinions=2C Get Free ThinkGeek Gift Certificates! Click to find = =3E out more =3E http=3A//productguide=2Eitmanagersjournal=2Ecom/guidepromo=2Etmpl =3E =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F= =5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F=5F =3E Springframework-developer mailing list =3E Springframework-developer=40lists=2Esourceforge=2Enet =3E https=3A//lists=2Esourceforge=2Enet/lists/listinfo/springframework-de= veloper =3E |