I tried os.flush() as you recommended previously, it did not work. I
even set large chunks and did System.gc() in the loop, that didn't
work. Then I even tried putting the System.gc() after I close the
connection, but the heap still remains quite large.

When I transfer a bunch photos (say, 50 for example) I see the heap
grow occasionally but shrink again staying within 5-8M. When sending 2
videos I can get the first one to work, but the heap never shrinks
down low enough before the next video tries to send and I get the
error. Granted, that is a moot point as any single large video would
fail and I need support for any large file.

Thanks!

On Mar 13, 5:05 am, Makas Tzavellas <makas.tzavel...@gmail.com> wrote:
> Hi,
>
> There is no guarantee that this will work, but try placing
> "os.flush()" in your loop. Which in theory tells the outputstream
> implementation to write out the buffered data.
>
> E.g
>
> while ((len = is.read(buffer)) != -1){
> os.write(buffer, 0, len);
> os.flush();
>
> }
>
> I haven't looked at the underlying implementation of org.apache.http
> package in Android. But perhaps it is worth investigating if you
> continue to have problems.
>
> Makas
> On Mar 13, 8:17 am, AuxOne <tyler.thack...@gmail.com> wrote:
>
> > I have some Android code that can sendfilesto my webserver using an
> >HttpsUrlConnection, but when it tries to send largerfilesI get an
> > OutOfMemory exception when opening the OutputStream. Can anyone offer
> > some assistance?
>
> > It looks something like this:
>
> > httpConn = (HttpsURLConnection) new URL(uri).openConnection();
> > httpConn.setDoInput(true);
> > httpConn.setDoOutput(true);
> > httpConn.setUseCaches(false);
> > httpConn.setRequestMethod("POST");
>
> > This is where I try different things. The closes solution has been:
> > httpConn.setChunkedStreamingMode(1024);
> > In this case, I don't get the OutOfMemory immediately when opening the
> > OutputStream, but I see the heap growing as I os.write() and it
> > eventually runs out.
>
> > httpConn.connect();
> > OutputStream os = httpConn.getOutputStream();
> > byte[] buffer = new byte[4096];
> > int len;
> > while ((len = is.read(buffer)) != -1){
> > os.write(buffer, 0, len);}
>
> > os.flush();
>
> > Each time I open the .getOutputStream() the contents of the file I am
> > trying to send is loaded into memory, per the discussion here (http://
> > bugs.sun.com/bugdatabase/view_bug.do?bug_id=4212479) -- so I go out of
> > memory.
>
> > My server supports HTTP 1.1. I've tried the following code.
> > 1. httpConn.setRequestProperty("Transfer-Encoding","chunked");
> > 2. httpConn.setChunkedStreamingMode(1024);
> > 3. httpConn.setRequestProperty("Content-Length", length);
> > 4. httpConn.setFixedLengthStreamingMode(1024)
> > 5. Combo of 1+2.
> > 6. Combo of 3+4
>
> > Can anyone offer any assistance?! It seems like no matter what, the
> > data going to the OutputStream is being buffered. ChunkedStreamMode
> > seems to just buffer it in pieces, whereas it would otherwise buffer
> > it all at once. Both go out of memory.
>
> > Thanks in advance.
>
> > PS> I have similar code for J2ME and memory has not been a problem.
> > Also, if I try to send two medium sizedfilesin a row, the first one
> > makes it, but then the heap doesn't seem to compact and the second one
> > fails.
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to