See WeakHashMap documentation. If the key is the same object as the objectid the keys can never be collected.
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com> ---
.../src/org/spearce/jgit/lib/Repository.java | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
Show changes to org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java +3 −1
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java index f7c470d..8b1f42c 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java @@ -199,7 +199,9 @@ public class Repository { final byte[] raw = or.getBytes(); if (Constants.TYPE_COMMIT.equals(or.getType())) { ret = new Commit(this, id, raw); - cache.put(id, ret); + // The key must not be the referenced strongly + // by the value in WeakHashMaps + cache.put(new ObjectId(id.getBytes()), ret); return ret; } throw new IncorrectObjectTypeException(id, Constants.TYPE_COMMIT);