Reputation: 1396
So I'm using a service and at some point I need to run this:
Bitmap wallpaperBitmap = ((BitmapDrawable) WallpaperManager
.getInstance(getApplicationContext()).getDrawable()).getBitmap();
Then set this bitmap as background to a view that I keep it in my service using
View.setBackground(new BitmapDrawable(res, wallpaperBitmap));
Thing is that as soon as I get the drawable from WallpaperManager
my service's RAM usage jumps up because the wallpaperBitmap
is kept in memory. Or probably the drawable returned by the WallpaperManager
is the one kept in memory (I'm not exactly sure). How can I release the memory from this background?
To be noted: I do change the background of the view to a color after some time and the bitmap no longer shows as the background but the RAM is never freed. Also I tried `wallpaperBitmap.recycle()` but the memory is still not cleared. How do I release that memory from the WallpaperManager?
Upvotes: 3
Views: 900
Reputation: 2856
You can try this. It will immediately frees the memory
bitmap.recycle();
bitmap = null;
Upvotes: 0
Reputation: 70
You can do bitmap.recycle(). It frees the object associated with the bitmap and clears the reference to pixel data thereby allowing it to be grabage collected.
Upvotes: 1