Skip to content

Commit

Permalink
Free memory when the view is detached. Fixes #1004 (#1005)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow authored Nov 11, 2019
1 parent 9da3dad commit cd257ad
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions source/SkiaSharp.Views/SkiaSharp.Views.Android/SKCanvasView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,18 @@ protected virtual void OnDraw(SKSurface surface, SKImageInfo info)
{
}

protected override void OnDetachedFromWindow()
{
FreeBitmap();

base.OnDetachedFromWindow();
}

protected override void Dispose(bool disposing)
{
if (disposing)
{
FreeBitmap();
}

base.Dispose(disposing);
}

Expand All @@ -156,9 +162,7 @@ private void FreeBitmap()
{
// free and recycle the bitmap data
if (bitmap.Handle != IntPtr.Zero && !bitmap.IsRecycled)
{
bitmap.Recycle();
}
bitmap.Dispose();
bitmap = null;
}
Expand Down

0 comments on commit cd257ad

Please sign in to comment.