* [JGIT PATCH] Use SoftReference in WindowCache to keep Repository around
@ 2009-08-12 17:03 Shawn O. Pearce
0 siblings, 0 replies; only message in thread
From: Shawn O. Pearce @ 2009-08-12 17:03 UTC (permalink / raw)
To: Robin Rosenberg; +Cc: git
This is meant to be a memory sensitive cache that holds the
Repository object around if there is JVM memory available to
store it, and any packs it might have loaded.
Unfortunately I wrote the cache with a WeakReference, which
is cleared as soon as there are no more strong references to
the Repository. This isn't very suitable for use in a server
application or a GUI which is depending upon this cache to hold
frequently accessed Repositories for near-term reuse.
Switching these to SoftReference, which is what we also use in the
WindowCache, permits the JVM to retain these Repository objects until
the JVM is low on memory and the Repository is not strongly held.
This new behavior is more consistent with the name and intent of
the class.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/lib/RepositoryCache.java | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryCache.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryCache.java
index 386f798..3aaffee 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryCache.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryCache.java
@@ -40,7 +40,7 @@
import java.io.File;
import java.io.IOException;
import java.lang.ref.Reference;
-import java.lang.ref.WeakReference;
+import java.lang.ref.SoftReference;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -156,7 +156,7 @@ private Repository openRepository(final Key location,
db = ref != null ? ref.get() : null;
if (db == null) {
db = location.open(mustExist);
- ref = new WeakReference<Repository>(db);
+ ref = new SoftReference<Repository>(db);
cacheMap.put(location, ref);
}
}
@@ -167,7 +167,7 @@ private Repository openRepository(final Key location,
private void registerRepository(final Key location, final Repository db) {
db.incrementOpen();
- WeakReference<Repository> newRef = new WeakReference<Repository>(db);
+ SoftReference<Repository> newRef = new SoftReference<Repository>(db);
Reference<Repository> oldRef = cacheMap.put(location, newRef);
Repository oldDb = oldRef != null ? oldRef.get() : null;
if (oldDb != null)
--
1.6.4.225.gb589e
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2009-08-12 17:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-12 17:03 [JGIT PATCH] Use SoftReference in WindowCache to keep Repository around Shawn O. Pearce
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox