Skip to content

Commit 360567b

Browse files
ctomcbrmeyer
authored andcommitted
HHH-8363 Some more mem leak fixes
1 parent fa341c6 commit 360567b

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
public class ClassLoaderServiceImpl implements ClassLoaderService {
5353
private static final Logger log = Logger.getLogger( ClassLoaderServiceImpl.class );
5454

55-
private final AggregatedClassLoader aggregatedClassLoader;
55+
private AggregatedClassLoader aggregatedClassLoader;
5656

5757
private final Map<Class, ServiceLoader> serviceLoaders = new HashMap<Class, ServiceLoader>();
5858

@@ -172,7 +172,7 @@ private static ClassLoader locateTCCL() {
172172
}
173173

174174
private static class AggregatedClassLoader extends ClassLoader {
175-
private final ClassLoader[] individualClassLoaders;
175+
private ClassLoader[] individualClassLoaders;
176176

177177
private AggregatedClassLoader(final LinkedHashSet<ClassLoader> orderedClassLoaderSet) {
178178
super( null );
@@ -227,7 +227,11 @@ protected Class<?> findClass(String name) throws ClassNotFoundException {
227227

228228
throw new ClassNotFoundException( "Could not load requested class : " + name );
229229
}
230-
}
230+
231+
public void destroy() {
232+
individualClassLoaders = null;
233+
}
234+
}
231235

232236
@Override
233237
@SuppressWarnings( {"unchecked"})
@@ -343,6 +347,10 @@ public void stop() {
343347
serviceLoader.reload(); // clear service loader providers
344348
}
345349
serviceLoaders.clear();
350+
if (aggregatedClassLoader!=null){
351+
aggregatedClassLoader.destroy();
352+
aggregatedClassLoader = null;
353+
}
346354
}
347355

348356
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,10 @@ public void destroy() {
278278
serviceBindingList.clear();
279279
}
280280
serviceBindingMap.clear();
281-
282-
parent.destroy();
281+
282+
if (parent!=null){
283+
parent.destroy();
284+
}
283285
}
284286

285287
@Override

hibernate-envers/src/main/java/org/hibernate/envers/configuration/spi/AuditConfiguration.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package org.hibernate.envers.configuration.spi;
2525

26+
import java.util.HashSet;
2627
import java.util.Map;
2728
import java.util.Properties;
2829
import java.util.WeakHashMap;
@@ -62,7 +63,7 @@ public class AuditConfiguration {
6263
private final RevisionInfoQueryCreator revisionInfoQueryCreator;
6364
private final RevisionInfoNumberReader revisionInfoNumberReader;
6465
private final ModifiedEntityNamesReader modifiedEntityNamesReader;
65-
private final ClassLoaderService classLoaderService;
66+
private ClassLoaderService classLoaderService;
6667

6768
public AuditEntitiesConfiguration getAuditEntCfg() {
6869
return auditEntCfg;
@@ -184,4 +185,13 @@ public synchronized static AuditConfiguration getFor(Configuration cfg, ClassLoa
184185

185186
return verCfg;
186187
}
188+
189+
public void destroy() {
190+
for (Map.Entry<Configuration, AuditConfiguration> c: new HashSet<Map.Entry<Configuration, AuditConfiguration>>(CFGS.entrySet())){
191+
if (c.getValue() == this){//this is nasty cleanup fix, whole static CFGS should be reworked
192+
CFGS.remove(c.getKey());
193+
}
194+
}
195+
classLoaderService = null;
196+
}
187197
}

hibernate-envers/src/main/java/org/hibernate/envers/event/spi/EnversIntegrator.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class EnversIntegrator implements Integrator {
5353
* should happen or not. Default is true
5454
*/
5555
public static final String AUTO_REGISTER = "hibernate.listeners.envers.autoRegister";
56+
private AuditConfiguration enversConfiguration;
5657

5758
@Override
5859
public void integrate(
@@ -72,7 +73,7 @@ public void integrate(
7273
final EventListenerRegistry listenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
7374
listenerRegistry.addDuplicationStrategy( EnversListenerDuplicationStrategy.INSTANCE );
7475

75-
final AuditConfiguration enversConfiguration = AuditConfiguration.getFor(
76+
enversConfiguration = AuditConfiguration.getFor(
7677
configuration,
7778
serviceRegistry.getService(
7879
ClassLoaderService.class
@@ -112,7 +113,7 @@ EventType.POST_UPDATE, new EnversPostUpdateEventListenerImpl(
112113

113114
@Override
114115
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
115-
// nothing to do afaik
116+
enversConfiguration.destroy();
116117
}
117118

118119
/**

0 commit comments

Comments
 (0)