[hibernate-dev] Static meta-model and references to SessionFactoryImpl

Gunnar Morling gunnar.morling at googlemail.com
Wed Jul 20 16:38:52 EDT 2011


Hi,

to answer my own question: The meta-model is re-created whenever
EntityManagerFactoryImpl is instantiated. Hence old meta-model
elements will be GC'ed and with them the SessionFactoryImpl etc. (if
it was closed).

In my case now there was a static reference from application code to
one element from the meta-model, hindering that element and with it
the factory to be GC'ed.

-- Gunnar


2011/7/19 Gunnar Morling <gunnar.morling at googlemail.com>:
> Hi,
>
> while analyzing a memory leak I noticed that instances of the static
> JPA 2 meta model seem to hold references to Hibernate's session
> factory. In my case the path to the factory is the following:
>
> SingularAttributeImpl#attributeType ->
> EmbeddableTypeImpl#hibernateType -> ComponentType#typeScope ->
> TypeScopeImpl#factory
>
> Since the members of the meta model are static I think that means that
> the factory won't be GC'ed although it was closed by the application,
> hence consuming memory otherwise not needed anymore. WDYT, is this an
> issue that should be addressed? Or are the meta model instances
> removed at some point of time? I don't know really much about
> Hibernate Core, so I hope my questions are not completely clueless ;-)
>
> Thanks,
>
> --Gunnar
>



More information about the hibernate-dev mailing list