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>
This commit is contained in:
parent
b427e32c18
commit
7085c0e4ac
|
@ -78,8 +78,6 @@ public class ObjectWriter {
|
||||||
|
|
||||||
private final MessageDigest md;
|
private final MessageDigest md;
|
||||||
|
|
||||||
private final Deflater def;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an Object writer for the specified repository
|
* Construct an Object writer for the specified repository
|
||||||
* @param d
|
* @param d
|
||||||
|
@ -88,7 +86,6 @@ public ObjectWriter(final Repository d) {
|
||||||
r = d;
|
r = d;
|
||||||
buf = new byte[8192];
|
buf = new byte[8192];
|
||||||
md = Constants.newMessageDigest();
|
md = Constants.newMessageDigest();
|
||||||
def = new Deflater(r.getConfig().getCore().getCompression());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -309,6 +306,7 @@ ObjectId writeObject(final int type, long len, final InputStream is,
|
||||||
final DeflaterOutputStream deflateStream;
|
final DeflaterOutputStream deflateStream;
|
||||||
final FileOutputStream fileStream;
|
final FileOutputStream fileStream;
|
||||||
ObjectId id = null;
|
ObjectId id = null;
|
||||||
|
Deflater def = null;
|
||||||
|
|
||||||
if (store) {
|
if (store) {
|
||||||
t = File.createTempFile("noz", null, r.getObjectsDirectory());
|
t = File.createTempFile("noz", null, r.getObjectsDirectory());
|
||||||
|
@ -320,7 +318,7 @@ ObjectId writeObject(final int type, long len, final InputStream is,
|
||||||
|
|
||||||
md.reset();
|
md.reset();
|
||||||
if (store) {
|
if (store) {
|
||||||
def.reset();
|
def = new Deflater(r.getConfig().getCore().getCompression());
|
||||||
deflateStream = new DeflaterOutputStream(fileStream, def);
|
deflateStream = new DeflaterOutputStream(fileStream, def);
|
||||||
} else
|
} else
|
||||||
deflateStream = null;
|
deflateStream = null;
|
||||||
|
@ -374,6 +372,9 @@ ObjectId writeObject(final int type, long len, final InputStream is,
|
||||||
t.delete();
|
t.delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (def != null) {
|
||||||
|
def.end();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t == null)
|
if (t == null)
|
||||||
|
|
Loading…
Reference in New Issue