Question

Basically my app keeps crashing. However, all my activities have 'finish();', which should end the activity and release the memory (at least that's my understanding). In the same vein, my images are only a few hundred KB if that, saved in the PNG format.

My code has no immediate errors amongst the Java package explorer at least. In DDMS I get the errors listed in the title. Following questions and answers on here I followed the most logical steps for my project but it hasn't worked. So far i've checked image sizes (which are low file sizes) and i've added finish(); to my activities.

Essentially I get about 10 activities in and it crashes. I have a total of around 60 activities, each with a image, imagebutton, and a scrolltextview. Some occasionally have a image on screen that pauses and continues to the next activity. I would post code up, but there's no one page of code that's immediately relevant - or at least that i can parse.

As for the AVD it's just a mid-range with a low SD-Card memory, however, even on a real device from mid-to-high range, the app has the same issues.

Any help is appreciated!

Was it helpful?

Solution

I've seen that behavior quiet often, first of all let me tell you that finishing an activity doesn't necessarily mean that the OS will release the resources, OS is smart enough to leave some resources around in case that you might decide to open again that activity even when you previously destroyed it, now as you open more activities the OS could decide to completely let go some resources of previous "destroyed" activities since it might need those resources for the newest activity.

Regarding to your memory issue I'm almost sure it has to do with the Image Resizing Mechanism, even when your application has images with just a few KBs, those images might become several MBs if not stored in the proper drawable-folder, because the OS will try to resize those images to fit properly in your activity by using the formula: ImageWidth * ImageHeight * 4Bytes, 1Byte for Alpha/R/G/B, and in the DDMS by tracking the Heap you can notice if when you go to one activity the Heap increases stupidly fast.

In order to make sure the issue is not related to the Resizing Mechanism, put all your drawables in a folder named: drawable-nodpi (This way you tell the OS NOT TO RESIZE), if you see a huge difference in performance then it means that the problem is that your drawables are not properly designed in size per each screen density...

Hope this helps.

Regards!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top