pangula / osmdroid

Automatically exported from code.google.com/p/osmdroid
0 stars 0 forks source link

BitmapPool memory clearing #500

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. App with activities A and B

A opens up B which shows MapView. B is closed with finish() and extra memory 
clearing calls:

mMapView.getController().stopAnimation(false);
mMapView.getController().stopPanning();     
tileProvider.clearTileCache();
rl.removeView(mMapView);

mMapView = null;
rl = null;
tileProvider = null;

What is the expected output? What do you see instead?

The problem is that currently there is no option to clear up BitmapPool, which 
leaves in memory ca. 5MB extra waste,

What version of the product are you using? On what operating system?

osmdroid SVN r1393, Android 4.0.

Please provide any additional information below.

BitmapPool memory could be released with the following code:

    public static void clearCache() {
        if (sInstance != null) {
            synchronized(sInstance.mPool) {
                while (!sInstance.mPool.isEmpty()) {
                    Bitmap bitmap = sInstance.mPool.remove();
                    bitmap.recycle();
                }
            }
            sInstance = null;
        }
    }

Original issue reported on code.google.com by jaanus.h...@gmail.com on 13 Dec 2013 at 12:02

GoogleCodeExporter commented 9 years ago
You are correct - we do need something like that. I will add a method but I am 
going to make it a member method rather than static.

Original comment by kurtzm...@gmail.com on 13 Dec 2013 at 3:32

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r1395.

Original comment by kurtzm...@gmail.com on 13 Dec 2013 at 3:34

GoogleCodeExporter commented 9 years ago
Hi,

Doesn't it have to be called somewhere centrally?

For example why not having a destroy method at MapView
which does all the proper memory clearing calls
and we call it at our activity finish?

Best regards, Emux

Original comment by devemu...@gmail.com on 13 Dec 2013 at 6:20

GoogleCodeExporter commented 9 years ago
BitmapPool is a singleton. This leads to the fact that the memory of bitmap 
pool is not reclaimed when activity is destroyed.
Wouldn't it be better to bind BitmapTool to instance of MapView, or to the 
context of activity?

Memory of the tile cache also requires to be reclaimed manually due to static 
instances of tile sources. That's bad.

Original comment by ls.illar...@gmail.com on 14 Dec 2013 at 12:41