• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Out Of Memory Issues

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't suspect any memory issues but you should generally close a stream if you opened it yourself.
 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A similar query was answered in a thread before. You can take a loot at it here.
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Images are contains directly binary data, so the answer is yes.
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic