HttpClient.execute throwing OutOfMemoryError

前端 未结 3 1125
醉话见心
醉话见心 2021-02-14 00:42

I\'ve an Android application that posting JSONObject as a entity by using ByteArrayEntity object. Here how it looks like:

post.setEntit         


        
3条回答
  •  伪装坚强ぢ
    2021-02-14 01:20

    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.

提交回复
热议问题