[JGIT PATCH] Use SoftReference in WindowCache to keep Repository around

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx>
---
 .../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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]