Memory allocation problems with android application

Stacker-flow :

I have an android application that performs image analysis, which is managed with an IntentService - the process takes a couple of seconds each time and works accurately and quickly.

But when the process is repeated in the app around 50 times (as illustrated) it begins to get very slow until the point in which the app and device becomes unusable. When the device is restarted and app opens again it runs as usual.

Inspecting with Android Studio I can see that each time I run the analysis that the memory allocation for the app goes up and up every time by around 1MB. So it is clearly running out of memory when it crashes.

I have used this flag on finishing the analysis and going to the result to try fix background activities;

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

which has had minimal effect, and I understand the IntentService manages itself shutting down. So not sure what else I can do to try and reduce the memory allocation or at least clear down allocation and stop adding to it?

Image Analysis Workflow

Further details:

  • The application is using the camera implementation based on Google Camera2
  • The analysis is done with a C++ library through the IntentService
Ali786 :

It seems you are not handling the resources (variables, image files,etc) properly, and its creating memory leaks in your application.

you can find here in this blog Written by Johan on handling the memory leaks in your application or see this SO Question.

Avoid memory leaks on Android

If the memory leaks are being generated in the c++ library then you can easily find the resource which is leaking the memory in debug mode.

After the result activity you should call the garbage collector as suggested by Grisgram and close any unused resources.

It would be good if you could provide the stack trace in the question.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=422647&siteId=1