HHH-8363 Some more mem leak fixes

This commit is contained in:
Tomaz Cerar 2013-09-06 20:26:01 +02:00 committed by Brett Meyer
parent fa341c66e9
commit 360567beac
4 changed files with 29 additions and 8 deletions

View File

@ -52,7 +52,7 @@ import org.jboss.logging.Logger;
public class ClassLoaderServiceImpl implements ClassLoaderService {
private static final Logger log = Logger.getLogger( ClassLoaderServiceImpl.class );
private final AggregatedClassLoader aggregatedClassLoader;
private AggregatedClassLoader aggregatedClassLoader;
private final Map<Class, ServiceLoader> serviceLoaders = new HashMap<Class, ServiceLoader>();
@ -172,7 +172,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
}
private static class AggregatedClassLoader extends ClassLoader {
private final ClassLoader[] individualClassLoaders;
private ClassLoader[] individualClassLoaders;
private AggregatedClassLoader(final LinkedHashSet<ClassLoader> orderedClassLoaderSet) {
super( null );
@ -227,7 +227,11 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
throw new ClassNotFoundException( "Could not load requested class : " + name );
}
}
public void destroy() {
individualClassLoaders = null;
}
}
@Override
@SuppressWarnings( {"unchecked"})
@ -343,6 +347,10 @@ public class ClassLoaderServiceImpl implements ClassLoaderService {
serviceLoader.reload(); // clear service loader providers
}
serviceLoaders.clear();
if (aggregatedClassLoader!=null){
aggregatedClassLoader.destroy();
aggregatedClassLoader = null;
}
}
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

View File

@ -278,8 +278,10 @@ public abstract class AbstractServiceRegistryImpl
serviceBindingList.clear();
}
serviceBindingMap.clear();
parent.destroy();
if (parent!=null){
parent.destroy();
}
}
@Override

View File

@ -23,6 +23,7 @@
*/
package org.hibernate.envers.configuration.spi;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.WeakHashMap;
@ -62,7 +63,7 @@ public class AuditConfiguration {
private final RevisionInfoQueryCreator revisionInfoQueryCreator;
private final RevisionInfoNumberReader revisionInfoNumberReader;
private final ModifiedEntityNamesReader modifiedEntityNamesReader;
private final ClassLoaderService classLoaderService;
private ClassLoaderService classLoaderService;
public AuditEntitiesConfiguration getAuditEntCfg() {
return auditEntCfg;
@ -184,4 +185,13 @@ public class AuditConfiguration {
return verCfg;
}
public void destroy() {
for (Map.Entry<Configuration, AuditConfiguration> c: new HashSet<Map.Entry<Configuration, AuditConfiguration>>(CFGS.entrySet())){
if (c.getValue() == this){//this is nasty cleanup fix, whole static CFGS should be reworked
CFGS.remove(c.getKey());
}
}
classLoaderService = null;
}
}

View File

@ -53,6 +53,7 @@ public class EnversIntegrator implements Integrator {
* should happen or not. Default is true
*/
public static final String AUTO_REGISTER = "hibernate.listeners.envers.autoRegister";
private AuditConfiguration enversConfiguration;
@Override
public void integrate(
@ -72,7 +73,7 @@ public class EnversIntegrator implements Integrator {
final EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
listenerRegistry.addDuplicationStrategy( EnversListenerDuplicationStrategy.INSTANCE );
final AuditConfiguration enversConfiguration = AuditConfiguration.getFor(
enversConfiguration = AuditConfiguration.getFor(
configuration,
serviceRegistry.getService(
ClassLoaderService.class
@ -112,7 +113,7 @@ public class EnversIntegrator implements Integrator {
@Override
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
// nothing to do afaik
enversConfiguration.destroy();
}
/**