1

What are the alternatives to send a big image from a midlet to servlet to prevent OutOfMemoryErrors?

djot
  • 2,952
  • 4
  • 19
  • 28
iberck
  • 2,372
  • 5
  • 31
  • 41
  • Can you explain how your current approach causes an OutOfMemoryError? Splitting the image into smaller pieces is what immediately springs to mind. – Paul Grime Feb 09 '12 at 20:59
  • The problem is that I am using the HTTP protocol and I can only send 1 request, therefore, although I split the image in parts, I have to rebuild it to write to the OutputStream. As you write it to the OutputStream, memory fills and gives OutOfMemoryError problems – iberck Feb 09 '12 at 21:27
  • You can send as many HTTP requests as you want in theory. Are you saying you have a restriction that you can only send one? Does the `OutOfMemoryError` occur when you rebuild the image, *or* when you write it to the OutputStream? I wouldn't have thought the `OutputStream.write` should cause OOME as it should be sending data in chunks and not all at once. – Paul Grime Feb 09 '12 at 21:34
  • I have understood that I can only send a request to the server and then receive a response. The OutOfMemoryError is on OutputStream.write. If you want to send the request in chunks, you have to make it "manual" with "Transfer-Encoding=chunked"... The problem is it isn't supported in Nokia s40 series – iberck Feb 09 '12 at 21:45
  • Unless the `OutputStream` is holding on to all the image data before it sends it over the network, then I would expect it to be flushing as it writes. That's why I'm surprised that you get the OOME when using `OutputStream.write()`. Although chunked encoding may not be supported directly by Nokia's APIs, you could write that layer yourself. You only need access to the output stream to set the correct headers and write the chunked data. – Paul Grime Feb 09 '12 at 21:51

0 Answers0