2

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

sschrass
  • 7,014
  • 6
  • 43
  • 62
horeaper
  • 361
  • 1
  • 16

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,304
  • 5
  • 27
  • 47
  • 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
  • 24,131
  • 15
  • 66
  • 118