Skip to content

Commit

Permalink
bugfix: added clearProperties(ClassLoader) to BeanELResolver to remov…
Browse files Browse the repository at this point in the history
…e ClassLoader leaks
  • Loading branch information
lprimak committed May 2, 2024
1 parent 8553855 commit 5a6f08c
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions api/src/main/java/jakarta/el/BeanELResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,24 @@ public Class<?> getCommonPropertyType(ELContext context, Object base) {
return Object.class;
}

/**
* Clears properties cache by class loader.
* To be called from the Container to clear the cache when ClassLoader is no longer in use
* <p>
* Even though {@link #properties} map is using {@link SoftReference} to store
* its cache content, GC may not clean the cache on its own. This is because
* the cache stores Class types, which hold a reference to its ClassLoader,
* which in turn is much heavier than the garbage collector believes.
* There may not be enough memory pressure to remove the Class element,
* and GC may not be able to clear the ClassLoader without help from this method.
*
* @param classLoader
*/
public void clearProperties(ClassLoader classLoader) {
properties.entrySet().removeIf(entry -> entry.getKey().getClassLoader() == classLoader);
properties.map.entrySet().removeIf(entry -> entry.getKey().getClassLoader() == classLoader);
}

private BeanProperty getBeanProperty(ELContext context, Object base, Object prop) {
String property = prop.toString();
Class<?> baseClass = base.getClass();
Expand Down

0 comments on commit 5a6f08c

Please sign in to comment.