[hibernate-issues] [Hibernate-JIRA] Commented: (HSEARCH-314) ThreadLocal in ContextHolder causes memory leak when deployed in a web container

François Terrier (JIRA) noreply at atlassian.com
Tue Dec 2 04:46:15 EST 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-314?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=31848#action_31848 ] 

François Terrier commented on HSEARCH-314:
------------------------------------------

Using a WeakHashMap in the ThreadLocal should do the trick, since as soon as the key is not referenced anymore, the value gets collected. However, in ContextHolder, the value which is stored in the WeakHashMap has a reference to its key, which prevents it from being collected. The faulty code is the following:

searchFactory = new SearchFactoryImpl( new SearchConfigurationFromHibernateCore( cfg ) );
contextMap.put( cfg, searchFactory );

SearchConfigurationFromHibernateCore keeps a reference to the key.

Regarding your last comment, how can I use the automatic registration of events ?

> ThreadLocal in ContextHolder causes memory leak when deployed in a web container
> --------------------------------------------------------------------------------
>
>                 Key: HSEARCH-314
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HSEARCH-314
>             Project: Hibernate Search
>          Issue Type: Bug
>          Components: engine
>    Affects Versions: 3.1.0.CR1
>         Environment: Hibernate 3.3.1.GA Tomcat 6.0.18 Spring 2.5.6 Java OpenJDK 1.6
>            Reporter: François Terrier
>
> The SearchFactory has a static ThreadLocal variables which holds a reference to the SearchFactoryImpl. The ThreadLocal is not cleared when the application is undeployed, causing a memory leak.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       




More information about the hibernate-issues mailing list