Results 1 to 4 of 4
- 08-18-2012, 11:53 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 2
- Rep Power
- 0
Clear bytearrayoutputstream, need help
Hello. I am new here, I am pretty big on other forums, but this is new.
I have worked on java for around 1 year.
Now here is my error: I transfer file through socket, by first writing it to a bytearrayoutputstream.
It writes OK and quick, but everything written to the bytearrayoutputstream stays there. Forever.Java Code:byte[] buffer = new byte[(int)file.length()]; ByteArrayOutputStream ous = new ByteArrayOutputStream(); InputStream ios = new FileInputStream(file); int read = 0; while ( (read = ios.read(buffer)) != -1 ) { ous.write(buffer, 0, read); } ous.flush(); byte[] ar = ous.toByteArray(); Connection.client.setSendBufferSize(ous.size()); Connection.client.getOutputStream().write(ar, 0, ous.size()); Connection.client.getOutputStream().flush(); ous.reset(); ous.close(); ios.close(); ios = null; ar = null; ous = null; System.gc();
If I write a 50 mb file, the memory goes up 50 mb, and in the end, it goes outofmemory.
I will happily explain more if you dont understand.
TL;DR
Dispose of the object
- 08-18-2012, 01:00 PM #2
Re: Clear bytearrayoutputstream, need help
Is this somehow related to Java sockets, everything written stays in memory - Stack Overflow and Java BufferedArrayOutputStream leaks in memory - Stack Overflow
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-18-2012, 07:14 PM #3
Member
- Join Date
- Aug 2012
- Posts
- 2
- Rep Power
- 0
Re: Clear bytearrayoutputstream, need help
nope.
- 08-18-2012, 10:15 PM #4
Re: Clear bytearrayoutputstream, need help
Can you demonstrate that with a small simple program that compiles and executes?everything written to the bytearrayoutputstream stays there. Forever.
Are you asking about data usage in an object
or about the JVM's memory usage.If you don't understand my response, don't ignore it, ask a question.
Similar Threads
-
Can you open ByteArrayOutputStream without creating file first.
By smitho in forum New To JavaReplies: 5Last Post: 09-05-2011, 01:38 PM -
What's the best way to clear a Socket?
By Joel in forum New To JavaReplies: 2Last Post: 06-22-2011, 05:30 PM -
Clear JSP usebean
By abbeywRCS in forum Advanced JavaReplies: 1Last Post: 05-16-2011, 08:18 PM -
Display sound data value from ByteArrayOutputStream
By cielle in forum Advanced JavaReplies: 2Last Post: 12-14-2010, 08:47 AM -
ByteArrayInputStream and ByteArrayOutputStream
By new_2_java in forum New To JavaReplies: 6Last Post: 07-31-2008, 10:02 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks