From a40082ca8dd2cc25281ecad06b233ed400c3996f Mon Sep 17 00:00:00 2001 From: Chris Bowditch Date: Tue, 20 Nov 2007 16:49:13 +0000 Subject: [PATCH] bug fix: memory leak in PropertyCache. Fix provided by Jeremias. There are still some thread synchronization issues to be addressed in the PropertyCache. See the following thread for details: http://mail-archives.apache.org/mod_mbox/xmlgraphics-fop-dev/200711.mbox/%3cBAY117-DAV109E36CC066889386AB917FB870@phx.gbl%3e git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@596739 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/fop/fo/properties/PropertyCache.java | 14 +++++++++----- status.xml | 4 ++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/java/org/apache/fop/fo/properties/PropertyCache.java b/src/java/org/apache/fop/fo/properties/PropertyCache.java index c1f9a985c..6d9adb998 100644 --- a/src/java/org/apache/fop/fo/properties/PropertyCache.java +++ b/src/java/org/apache/fop/fo/properties/PropertyCache.java @@ -76,6 +76,10 @@ public final class PropertyCache { this.ref = old.ref; this.hash = old.hash; } + + public boolean isCleared() { + return (ref == null || ref.get() == null); + } } @@ -116,10 +120,8 @@ public final class PropertyCache { int index = this.hash & (table.length - 1); CacheEntry first = table[index]; - WeakReference ref; for (CacheEntry e = first; e != null; e = e.next) { - ref = e.ref; - if (ref != null && ref.get() == null) { + if (e.isCleared()) { /* remove obsolete entry /* 1. clear value, cause interference for non-blocking get() */ e.ref = null; @@ -127,7 +129,9 @@ public final class PropertyCache { /* 2. clone the segment, without the obsolete entry */ CacheEntry head = e.next; for (CacheEntry c = first; c != e; c = c.next) { - head = new CacheEntry(c, head); + if (!c.isCleared()) { + head = new CacheEntry(c, head); + } } table[index] = head; segment.count--; @@ -177,7 +181,7 @@ public final class PropertyCache { /* launch cleanup in a separate thread, * so it acquires its own lock, and put() * can return immediately */ - Thread cleaner = new Thread(new CacheCleaner(hash)); + Thread cleaner = new Thread(new CacheCleaner(hash), "FOP PropertyCache Cleaner"); cleaner.start(); } } diff --git a/status.xml b/status.xml index 907487123..55e3f52fa 100644 --- a/status.xml +++ b/status.xml @@ -28,6 +28,10 @@ + + Memory Leak fixed in the Property Cache. Fixed by Jeremias Maerki. Reported and Tested By + Chris Bowditch. + Bugfix in tables: wrong element generation by the merging algorithm when glues must be produced to cope with conditional spaces. The corresponding length was added twice: one in -- 2.39.5