[ 
https://issues.apache.org/jira/browse/OPENJPA-2538?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14191591#comment-14191591
 ] 

Grzegorz Grzybek commented on OPENJPA-2538:
-------------------------------------------

As I suspected. There's no more refs, classloader is marked for gcollection, 
but {{PCRegistry._metas}} still contain old classes which are then put into 
{{org.apache.openjpa.meta.MetaDataRepository#register()}} by 
{{org.apache.openjpa.enhance.PCRegistry#addRegisterClassListener()}} so even if 
there's no more classloader leak, the classes from old {{BundleRevision}} of 
the bundle should be removed from {{PCRegistry._metas}} immediately when the 
bundle is updated.
That's why the following BundleActivator.stop is needed:
{code:java}
    @Override
    public void stop(BundleContext context) throws Exception {
        
org.apache.openjpa.enhance.PCRegistry.deRegister(context.getBundle().adapt(BundleWiring.class).getClassLoader());
    }
{code}

> Classloader memory leak in PCRegistry
> -------------------------------------
>
>                 Key: OPENJPA-2538
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2538
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: Enhance, osgi
>    Affects Versions: 2.3.0
>            Reporter: Grzegorz Grzybek
>            Assignee: Rick Curtis
>            Priority: Critical
>
> I'm using OpenJPA in OSGi environment (namely: JBoss Fuse 6.1). We had nasty 
> {{NullPointerException}} in Felix when trying to load source code during 
> initialization of class metadata. [This 
> line|https://github.com/apache/openjpa/blob/2.3.0/openjpa-kernel/src/main/java/org/apache/openjpa/meta/MetaDataRepository.java#L1614]
>  returned duplicate entity classes - half of them were from old revision of a 
> bundle and half - from new revision.
> I tracked down the problem to the point, where 
> {{org.apache.openjpa.enhance.PCRegistry#register()}} was invoked as part of 
> constructing new instances of entity classes (static initialization injected 
> during class enhancement). Although {{_metas}} is instance of 
> {{ConcurrentReferenceHashMap}} with weak keys, the keys (entity classes) had 
> other hard references too. Here's a list of the hard refs I got from simple 
> heap dump:
> * org.apache.openjpa.meta.MetaDataRepository#_impls
> * org.apache.openjpa.meta.InheritanceComparator#_base
> * org.apache.openjpa.enhance.PCRegistry.Meta#pcSuper
> * org.apache.openjpa.meta.MetaDataRepository#_oids
> so on every bundle refresh we have next bunch of classes in {{_metas}}...



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to