Browse Source

Explicitly release resources used by java.util.zip.Deflater

Deflater can use significant amount of native (i.e. C) heap
space. Failure to promptly release this memory results
in native memory leak in some cases, particularly severe for
VMs with large java max heap size. For example, running
Team->Commit in one of my EGit workspaces results in ~500M
java process size increase without any significant change
to amount of used java heap when JVM is started with -Xmx1024m.

Change-Id: I649679a8df5683ebedd9380d703513d31c625932
Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.7
Igor Fedorenko 15 years ago committed by Shawn O. Pearce
parent
commit
7085c0e4ac
  1. 9
      org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectWriter.java

9
org.eclipse.jgit/src/org/eclipse/jgit/lib/ObjectWriter.java

@ -78,8 +78,6 @@ public class ObjectWriter {
private final MessageDigest md;
private final Deflater def;
/**
* Construct an Object writer for the specified repository
* @param d
@ -88,7 +86,6 @@ public class ObjectWriter {
r = d;
buf = new byte[8192];
md = Constants.newMessageDigest();
def = new Deflater(r.getConfig().getCore().getCompression());
}
/**
@ -309,6 +306,7 @@ public class ObjectWriter {
final DeflaterOutputStream deflateStream;
final FileOutputStream fileStream;
ObjectId id = null;
Deflater def = null;
if (store) {
t = File.createTempFile("noz", null, r.getObjectsDirectory());
@ -320,7 +318,7 @@ public class ObjectWriter {
md.reset();
if (store) {
def.reset();
def = new Deflater(r.getConfig().getCore().getCompression());
deflateStream = new DeflaterOutputStream(fileStream, def);
} else
deflateStream = null;
@ -374,6 +372,9 @@ public class ObjectWriter {
t.delete();
}
}
if (def != null) {
def.end();
}
}
if (t == null)

Loading…
Cancel
Save