2

Do I still need to call Bitmap.Dispose() after Bitmap.Recycle()? Or just Bitmap.Dispose() is enough?

sschrass
  • 6,713
  • 6
  • 42
  • 58
horeaper
  • 342
  • 1
  • 14

2 Answers2

3

According to Android documentation Bitmap.Recycle() should be enough:

Free the native object associated with this bitmap, and clear the reference to the pixel data.

Mono for Android documentation says exactly the same.

Also, this question gets a little further on how Bitmap.Recycle works.

Community
  • 1
  • 1
Narcís Calvet
  • 7,171
  • 5
  • 27
  • 46
  • After replacing the old code `bitmap?.Dispose()` to `bitmap?.Recycle()` the app I'm fixing acts weirdly. Also, the bitmap gets distorted – mr5 Aug 17 '17 at 01:35
2

Another solution could be to wrap in a using statement:

using (var bm = new Bitmap(..))
{
    // Do stuff with the Bitmap here
}

Just remember that when you leave the scope of the using statement, the Bitmap will probably be garbage collected. So if you are just drawing it to a Canvas or something this is a nice way to do it.

Cheesebaron
  • 23,388
  • 14
  • 64
  • 113