Firstly I apologize for the size of this post in advance but some may find it useful. It's doesn't really meet the criteria for a stack overflow question so I thought I'd post it here.
I have just spent the last two days hunting down a problem that appeared when using Android 1.6 on the emulator (I don't have a real device to try it on).
I have been writing a menu system that uses bitmaps as a template and adds text for options, there can be any number of options so potentially loads of Bitmaps, so I decided to create each bitmap, only when necessary and store it to DirExternal.
I needed three bitmaps stored internally, the template, the current menu as I wanted to be able to scroll it by drawing it in various places across a canvas and the one that actually resides in the panel that the canvas is attached to.
The total size of these 3 bitmaps is about 2.4Mb.
This worked perfectly on all but Android 1.6 which gave an out of memory loading bitmap error consistently after loading the 4th menu. Which I thought was strange as it obviously could cope with holding the 3 bitmaps at once.
For this menu I have implemented a complex map which holds views and other maps so I thought memory leaks may be a possibility if I'd done it incorrectly, I searched the internet and found an excellent guide on StackOverflow here, but it turned up nothing.
I then looked at the memory heap that was available in the DDMS (mentioned in the SO post). The only thing that seemed strange was that in 1.6 the garbage collection didn't appear to happen as often.
I found a call on Android Developers site to System.gc that suggest to the OS that now would be a good time to run garbage collection. Implemented that via reflection after loading a bitmap and hey presto, the problem seems to have dissappeared!
I really didn't want to give up on Android 1.6 as there must be loads of users that still have that.
I've posted this for two reasons, first it may help someone else if you get into the same situation and second, someone with more knowledge of Android may say this is the wrong approach and provide a better solution.
I have just spent the last two days hunting down a problem that appeared when using Android 1.6 on the emulator (I don't have a real device to try it on).
I have been writing a menu system that uses bitmaps as a template and adds text for options, there can be any number of options so potentially loads of Bitmaps, so I decided to create each bitmap, only when necessary and store it to DirExternal.
I needed three bitmaps stored internally, the template, the current menu as I wanted to be able to scroll it by drawing it in various places across a canvas and the one that actually resides in the panel that the canvas is attached to.
The total size of these 3 bitmaps is about 2.4Mb.
This worked perfectly on all but Android 1.6 which gave an out of memory loading bitmap error consistently after loading the 4th menu. Which I thought was strange as it obviously could cope with holding the 3 bitmaps at once.
For this menu I have implemented a complex map which holds views and other maps so I thought memory leaks may be a possibility if I'd done it incorrectly, I searched the internet and found an excellent guide on StackOverflow here, but it turned up nothing.
I then looked at the memory heap that was available in the DDMS (mentioned in the SO post). The only thing that seemed strange was that in 1.6 the garbage collection didn't appear to happen as often.
I found a call on Android Developers site to System.gc that suggest to the OS that now would be a good time to run garbage collection. Implemented that via reflection after loading a bitmap and hey presto, the problem seems to have dissappeared!
I really didn't want to give up on Android 1.6 as there must be loads of users that still have that.
I've posted this for two reasons, first it may help someone else if you get into the same situation and second, someone with more knowledge of Android may say this is the wrong approach and provide a better solution.