File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Performance and the fly likes Out Of Memory Issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Out Of Memory Issues" Watch "Out Of Memory Issues" New topic
Author

Out Of Memory Issues

Abhishek Rath
Ranch Hand

Joined: Nov 22, 2007
Posts: 38
Hi

We are creating an image using netchart Pro API and then writing that Image to the OutputStream.
The code is as follows

OutputStream os = response.getOutputStream();
os.write(sgi.getImage());

Where the sgi is a netchart pro image object (png).The Image size is more than 10 MB.

We are not closing and flushing the OutputStream object after the above operation.Will this cause any memory leackage or out of memory issues?
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
I don't suspect any memory issues but you should generally close a stream if you opened it yourself.


JDBCSupport - An easy to use, light-weight JDBC framework -
Anirvan Majumdar
Ranch Hand

Joined: Feb 22, 2005
Posts: 261
A similar query was answered in a thread before. You can take a loot at it here.
Rajneesh Kumar Rajput
Ranch Hand

Joined: Feb 25, 2009
Posts: 39
well if you have posted this, you must have seen OutOfMemory as well while running the code?

The code that you are showing should not cause out Of Memory at all, but that different API that you are using to create an image of 10 MB will be the main suspect if you encountered an Out Of Memory.
Abhishek Rath
Ranch Hand

Joined: Nov 22, 2007
Posts: 38
Yes we are seeing Out of memory in the log.

Can you please let me know if we add a image of 10 MB in the output stream and then donot close and flush it then it will be there in the JVM and if the concurrent user (around 200) doing the same operation (viewing the image) for a long time then the memory usage (occupied by the stream object) will be high and it might lead to Out of memory exception.

Please share your thought.

Rajneesh Kumar Rajput
Ranch Hand

Joined: Feb 25, 2009
Posts: 39
Well I would say, over here closing/not closing stream could not be cause of out of Memory. most of output stream source code does not do anything while you close stream. it is blank implemented in sub classes.


And look for your example, that depends on the scope where image is being created/loaded.

If it is per user (per request) a different instance, will reach max usage of memory 200*10 = 2000 MB (~2GB).
is this right?

either look for current memory allocated to your JVM?

further analysis you need a tool like JProve etc or try to check jheap and jstate map to see which and how many objects are lying in the memory with this operation.
Abhishek Rath
Ranch Hand

Joined: Nov 22, 2007
Posts: 38
Thanks for the quick reply.

It is per request i.e. a new image is created per user's request. The current heap size on JVM is 256 MB.

We are scanning our application with JPROBE tool.

Can you please tell me if we write the image in the output stream , then will the size of the stream will be the size of image?
Rajneesh Kumar Rajput
Ranch Hand

Joined: Feb 25, 2009
Posts: 39
Images are contains directly binary data, so the answer is yes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Out Of Memory Issues