PGWelch / jspf

Automatically exported from code.google.com/p/jspf
4 stars 1 forks source link

ClassLoader does not release memory for unused classes #20

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
See this report from one of our users:

> I've found I can work around this with a much narrower search
> ("classpath://org.systemsbiology.[project name].plugins.*"), but I'm
> worried this isn't a stable solution (although there's no reason it
> shouldn't be). Actually, never mind, it's apparently failing to do a *
> match on classes at that point; I'll experimentally throw in the name
> of my actual plugin class and see if it's just not wildcarding, or if
> I simply screwed up the class search.

> What would I need to do to make a classpath://* search work- is there
> any strategy other than bumping up the PermGen space, and if not, what
> size should I set it to? Is there some plan to rework the loading
> algorithm to save memory by apparently wasting it, and- after a
> classloader contains too many classes- archive the names of found
> plugin classes, drop the classloader and all references to the plugin
> classes, and create a new one with a targeted search for just the
> found plugins, and then another new one to continue the search? This
> should allow the original classloader, and all the "oops, not a
> plugin" classes to get garbage-collected.

Original issue reported on code.google.com by r.biedert on 16 Nov 2010 at 8:33

GoogleCodeExporter commented 9 years ago
And yet another bug report:

Hi, 
I tried to create a new simple project following your video example, 
but I encountered a problem with this line: 
pluginManager.addPluginsFrom(new URI("classpath://*")); 
here is a sample of my code - well, it is not a sample, it is the 
majority of my program :): 
   PluginManager pluginManager = 
PluginManagerFactory.createPluginManager(); 
   pluginManager.addPluginsFrom(new URI("classpath://*")); 
   MyPluginable plugin = pluginManager.getPlugin(MyPluginable.class); 
   System.out.println(plugin.sayHello()); 
(where MyPluginable is my interface) 
the output of my program is: 
null 
Exception in thread "main" java.lang.OutOfMemoryError: PermGen space 
the "null" output is printed on the line containing 
"pluginManager.addPluginsFrom(new URI("classpath://*"))" 
I tried to run this code in Intellij  (the output was as I wrote 
above) and then in Netbeans, where the output was: 
null 
Hello world! 
I suspected problems with classpath, so using this method from this 
site: http://www.java-tips.org/java-se-tips/java.lang/how-to-print-classpat... 
I printed the whole classpath during program running - in IntelliJ it 
printed several jar files and the correct location of .class files: 
/C:/Program%20Files/Java/jdk1.6.0_21/jre/lib/alt-rt.jar 
/C:/Program%20Files/Java/jdk1.6.0_21/jre/lib/charsets.jar 
/C:/Program%20Files/Java/jdk1.6.0_21/jre/lib/deploy.jar 
/C:/Program%20Files/Java/jdk1.6.0_21/jre/lib/javaws.jar 
/C:/Program%20Files/Java/jdk1.6.0_21/jre/lib/jce.jar 
/C:/Program%20Files/Java/jdk1.6.0_21/jre/lib/jsse.jar 
/C:/Program%20Files/Java/jdk1.6.0_21/jre/lib/management-agent.jar 
/C:/Program%20Files/Java/jdk1.6.0_21/jre/lib/plugin.jar 
/C:/Program%20Files/Java/jdk1.6.0_21/jre/lib/resources.jar 
/C:/Program%20Files/Java/jdk1.6.0_21/jre/lib/rt.jar 
/C:/Program%20Files/Java/jdk1.6.0_21/jre/lib/ext/dnsns.jar 
/C:/Program%20Files/Java/jdk1.6.0_21/jre/lib/ext/localedata.jar 
/C:/Program%20Files/Java/jdk1.6.0_21/jre/lib/ext/sunjce_provider.jar 
/D:/skola/BAKALARKA/pokusPlugin/out/production/pokusPlugin/ 
-------------------- class files are here (what a surprise) 
/D:/skola/BAKALARKA/pokusPlugin/lib/dist/jspf.core-1.0.0.jar 
/C:/Program%20Files%20(x86)/JetBrains/IntelliJ%20IDEA%2010.0/lib/ 
idea_rt.jar 
when I tried to print classpath in Nebeans, it printed only this: 
/D:/skola/BAKALARKA/pokusPlugin/lib/dist/jspf.core-1.0.0.jar 
/D:/skola/BAKALARKA/pokusPlugin/build/classes/ 
/D:/skola/BAKALARKA/pokusPlugin/src/ 
please notice that in Netbeans, there are (almost) no jar files 
so my questions are: 
- is it OK, when there are many jar files in classpath? it seems to 
me, that exactly this scenario causes OutOfMemoryError 
- do you see something wrong with my code? why is there always that 
"null" in output and how to get rid of that OutOfMemoryError :) 
thanks a lot

Original comment by r.biedert on 11 Jan 2011 at 8:20

GoogleCodeExporter commented 9 years ago
1.0.0 RC2 should contain a workaround for at least large default classpaths. 
Please report your results!

Original comment by r.biedert on 11 Jan 2011 at 9:26

GoogleCodeExporter commented 9 years ago
And 1.0.0 RC3 contains a workaround that actually works (see forum 'problem 
loading plugins - OutOfMemoryError, etc.'). Lowering priority. 

Original comment by r.biedert on 11 Jan 2011 at 12:24