K
kempshall
Is there any way to find out how the JVM is allocating memory?
In particular, I have a method that takes an open InputStream and an
open OutputStream as parameters and copies the contents of the
InputStream to the OutputStream. It looks something like this, with the
exception handling omitted for clarity:
byte[] buffer = new byte[1024];
int len;
while((len = inputStream.read(buffer)) >= 0) {
outputStream.write(buffer, 0, len);
outputStream.flush();
}
out.flush();
The problem is that when the InputStream is connected to a huge data
source, like inputStream = new FileInputStream("largeFile.dat"), the
method throws an OutOfMemoryError after processing somewhere between 37
and 38 megabytes. I'm trying to find the memory "leak," but I'm out of
ideas. Does anybody have some suggestions?
Thanks.
In particular, I have a method that takes an open InputStream and an
open OutputStream as parameters and copies the contents of the
InputStream to the OutputStream. It looks something like this, with the
exception handling omitted for clarity:
byte[] buffer = new byte[1024];
int len;
while((len = inputStream.read(buffer)) >= 0) {
outputStream.write(buffer, 0, len);
outputStream.flush();
}
out.flush();
The problem is that when the InputStream is connected to a huge data
source, like inputStream = new FileInputStream("largeFile.dat"), the
method throws an OutOfMemoryError after processing somewhere between 37
and 38 megabytes. I'm trying to find the memory "leak," but I'm out of
ideas. Does anybody have some suggestions?
Thanks.