6 Replies Latest reply on Oct 31, 2012 12:36 AM by Ron Sigal

    PermGen Space: OutOfMemory caused by loading the same class multiple times

    Fabian Epp Newbie

      Hello Community,

       

      in our situation we have some server side classes which the osgi-client doesn´t have in it´s classpath. The client knows only its interfaces. The implementations will be loaded from server via Remote Class Loading.

       

      Now the problem is, when we call a server method which returns a certain implementation, the following scenario happens::

       

      1.) On each server call, a new ClassLoader will be created which loads all classes which is needed to create a single instance of the requested type.

      2.) At the next server call, the previous loaded classes are not reused. Instead a new ClassLoader is created which loads and stores the same classes again

      3.) If the loaded instances are remembered in a Collection the Garbage Collector has no chance to unload the classes because there is always exactly one existing reference.

      --> So, the Perm Gen Space increases and increases till we get an PermGenSpace Out Of Memory Exception

       

      So, my question is:

       

      Is it possible that the same classloader load all classes so that one class is only one time?

      How can it be configured?

       

      I´m happy about every solution.

       

      Thank you for your help:

       

      Fabian