views:

87

answers:

1

I have an app that uses quite a few graphics in it.

When I open and close my app repeatedly on my emulator (1.5 - 2.2) it runs fine and by checking the heap I can see everything is being cleaned and gc'd properly.

However, when I run my app on an HTC Aria phone (2.1) the app crashes every time I try to re-open it. When I look at the heap I can see that objects are NOT being cleaned up like they are in the emulator.

Does anyone know why this behavior could be happening? I did try it on another HTC Aria (a friends) and it crashed the same way as on my phone so I think it's not just isolated to my particular phone.

Any thoughts or ideas would be really appreciated on why things are cleaning up properly on the emulator, but not on my phone. One thing to note, is that I DID have it working and gc'ing fine on my phone a few days ago and I didn't change much and now it's not working on my phone so it's a bit of a mystery to me.

Thanks!

Note:
The crash is caused by an OutOfMemory Exception. I'm pre-loading a handful of graphics, and there's not enough memory for two instances of the application to be running at the same time so it's crashing because the 1st instance of the application was not cleaned up properly.

A: 

You have several emulators, all running just this app, closing it and start it again. Your Android device has several processes running the same time, like background sync, Facebook notification, Twitter notification, Calendar sync, Contacts sync and the like.

One way to look at this is to try to mimic your Android device state on your different emulators, and see if you can get the same error on the emulators. Use some apps that sync in the background and others who use a lot of memory. Then you have a testing environment that mimics the real world, and you can change your app up to a state where it doesn't crash. Maybe downsize the images as much as you can to ease memory usage.

Remember, you can never force the Garbace Collector to start. You can only tell the system that it is possible to collect this garbage.

BennySkogberg
This is a very good point that I had not thought of. Thanks!
justinl