I\'ve an Android application that posting JSONObject
as a entity by using ByteArrayEntity
object. Here how it looks like:
post.setEntit
Android devices have a per-process memory limit. The default default is 24MB, but some devices have a lower value, eg 16MB or perhaps lower. The X10i appears to have 384MB RAM, which is low for a modern Android device (1GB is now standard), and this may place additional constraints.
I would suggest:
You may find that, just before you are making this call, you are already at the upper limit of memory; the initialisation of the HTTPClient and the call might take you just over the limit. This will be more likely if the OOM occurs on the first call.
If this happens only sporadically, or after a number of calls, you might have a memory leak. DDMS will help you track that down using the get allocations feature.
On the surface, only 200 bytes which are allocated not very often will not run the process out of memory even on Android. Therefore one of these assumptions is wrong. Most likely one of the following is true:
1) More than 200 bytes is being allocated in the failure case (for example, is a new HttpClient being allocated for every call).
2) This code is getting called very often
3) There is already a memory problem (like with images) and this was just the last allocation that took the app past its limits.
How many times has this line of code been the culprit of this problem? If the answer is many then 1) or 2) look likely. Since we do not have all the apps code it is hard to diagnose, but look to the event/circumstance that triggers this code -- is it getting called from a touch or move -- and if so is this happening every millisecond as the user drags their finger across the screen because there is no sleep in the onTouch loop? This is the kind of thing that could vary from platform to platform.
If this line of code has only caused the problem once or twice it may be time to look for a general memory usage problem. Try to determine how close to the memory limit the application is. The allowance varies with Android version, so this may be another reason why you don't see it in the emulator. Try to test with the same Android version that is experiencing the problem.
In case of java.lang.OutOfMemoryError
it's likely that your application keeps references to objects which should be freed. Try to debug this application on this phone, not in emulator.