Results 1 to 8 of 8
Thread: Memory Leak Issue
- 01-09-2013, 10:15 AM #1
Member
- Join Date
- Jan 2013
- Location
- INDIA
- Posts
- 18
- Rep Power
- 0
Memory Leak Issue
Hi,
i am getting memory leak in this code
if i comment " baos.write(buffer, 0, count); " this line , there is no more memory leak. anyone have idea how to resolve memory leak, i need file in byte arrayJava Code:ByteArrayOutputStream baos = new ByteArrayOutputStream() buffer = new byte[5242880]; //1048576=1MB,5242880=5MB int xyza = 0 while ((count = zis.read(buffer)) != -1) { baos.write(buffer, 0, count); } bytes = baos.toByteArray(); baos.close() baos = null buffer = null
Thanks
- 01-09-2013, 10:17 AM #2
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Re: Memory Leak Issue
Erm... how did you "detect" your memory leak? It is quite tricky with a virtual machine... ^^
I can assure you that I do not see a leak here as such. Are you sure you clean up your OutputStream?
Maybe it overflows?
EDIT: Your code contains errors (line 1,3 is missing a ';' ) and is not executable. I can barely reproduce your problem.Last edited by Sierra; 01-09-2013 at 10:22 AM.
I like likes!.gif)
- 01-09-2013, 10:20 AM #3
Member
- Join Date
- Jan 2013
- Location
- INDIA
- Posts
- 18
- Rep Power
- 0
Re: Memory Leak Issue
i use Java Visual VM, (Sampler Tab) to identify memoery leak, it shows bytes array consumes lots of memory and in last i get memory error.
- 01-09-2013, 10:48 AM #4
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Re: Memory Leak Issue
Can you try to reduce your buffer size. Maybe your output stream buffer is overflowing. Usually you do not need such a large buffer.
Make sure your output stream is read, else you may buffer everything until you exceed the size of your JVM memory allocation.
You may checkout the -Xmx switch for using more memory for your JVM.Last edited by Sierra; 01-09-2013 at 10:59 AM. Reason: bold
I like likes!.gif)
- 01-09-2013, 11:11 AM #5
Member
- Join Date
- Jan 2013
- Location
- INDIA
- Posts
- 18
- Rep Power
- 0
Re: Memory Leak Issue
I am using groovy so no need for semicolon ";". :)
- 01-09-2013, 11:59 AM #6
AN21XX
- Join Date
- Mar 2012
- Location
- Munich
- Posts
- 297
- Rep Power
- 2
Re: Memory Leak Issue
I suggest you try a groovy forum then.
I like likes!.gif)
- 01-09-2013, 05:18 PM #7
Member
- Join Date
- Jun 2012
- Location
- Remscheid, Germany
- Posts
- 57
- Rep Power
- 0
Re: Memory Leak Issue
I would guess the problem is the internal bytearray inside of the ByteArrayOutputStream. This needs to get reallocated everytime it's to small for the additional data. Since you do not preallocate the BAOS it will grow very fast.
- 01-10-2013, 06:44 AM #8
Member
- Join Date
- Jan 2013
- Location
- INDIA
- Posts
- 18
- Rep Power
- 0
Similar Threads
-
avoid memory leak
By Sergey Livanov in forum Advanced JavaReplies: 10Last Post: 12-20-2011, 04:10 PM -
Memory leak in swing
By smeshram in forum AWT / SwingReplies: 7Last Post: 12-08-2011, 03:52 AM -
what are the memory profiling tools available that can help me detect memory leak?
By guest_user in forum New To JavaReplies: 1Last Post: 07-18-2011, 04:24 PM -
Help I have a memory leak...
By cdman52 in forum Java AppletsReplies: 10Last Post: 09-28-2009, 10:37 PM -
Memory Leak using a Swing Application Project
By iimasd in forum AWT / SwingReplies: 0Last Post: 11-27-2007, 10:20 AM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks