[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[Subclipse-dev] Memory leak in the method CmdLineClientAdapter.streamToByteArray()

From: Stefan Bicher <stefan.bicher_at_data-experts.de>
Date: Fri, 29 Aug 2008 11:46:49 +0200

Hi Subclipse-Developers,

I have no idea, if it´s a problem which is concerning you, but I
recognized a memory leak in the class
When the method streamToByteArray() is invoked with large streams, an
OutOfMemory-error occurs:

java.lang.OutOfMemoryError: Java heap space

I found this problem, when I tried to checkout a single 6.9-MB-File from
a repository. When the methode getContent() tries to change the
BufferedInputStream (which it gets from the command-line process) to a
ByteArrayInputStream, using the method streamToByteArray().

A workaround would be, to use a ByteArrayOutputStream instead of writing
all bytes from the stream into a Vector. For example:

private static byte[] streamToByteArray(InputStream stream) throws
IOException {

ByteArrayOutputStream out = new ByteArrayOutputStream();
int tempByte;
while (((tempByte = stream.read())) != -1) {

return out.toByteArray();

By the way: I wondered, why the InputStream, which is delivered from the
method SvnCommandLine.cat(..) is transferred to a ByteArrayInputStream.
In my opinion it would be nicer to return this InputStream directly, like:

public InputStream getContent(SVNUrl arg0, SVNRevision arg1) throws
SVNClientException {

try {
InputStream content = _cmd.cat(toString(arg0), toString(arg1));
return content;
} catch (IOException e) {
throw SVNClientException.wrapException(e);
} catch (CmdLineException e) {
throw SVNClientException.wrapException(e);

Well, but after all: Thanks for your great work on the svn-Client.



To unsubscribe, e-mail: dev-unsubscribe_at_subclipse.tigris.org
For additional commands, e-mail: dev-help_at_subclipse.tigris.org
Received on 2008-08-29 13:50:21 CEST

This is an archived mail posted to the Subclipse Dev mailing list.