Skip to content

SKCanvas native memory leak #192

Closed
Closed

Description

@mattleibow

There appears to be a memory leak when referencing SKCanvas.

Once you create an SKCanvas, I could not find any way to release memory used by it.
The following lines create a memory leak of 150 megs, attached is the allocations screenshot.

for (int i = 0; i < 10; i++) {
    using (SkiaSharp.SKBitmap bitmap = new SkiaSharp.SKBitmap(2000, 2000, false)) {
        using (var canvas = new SkiaSharp.SKCanvas(bitmap)) {

        }
    }
}

The following releases memory without issues.

for (int i = 0; i < 10; i++) {
    using (SkiaSharp.SKBitmap bitmap = new SkiaSharp.SKBitmap(2000, 2000, false)) {

    }
}

I have tried, flush, dispose, setting canvas to null, none of them are working. Basically, I'm trying to draw paths and save them as PNG.
Any ideas?

The original forum post: https://forums.xamarin.com/discussion/82206/skiasharp-skimage-encode-causes-memory-leaks

Activity

  1. added this to the 1.55.1 milestone on Nov 10, 2016
  2. mattleibow commented on Nov 10, 2016

    @mattleibow
    ContributorAuthor

    I think that this is a result of not dereferencing the underlying native canvas object.

  3. mattleibow commented on Nov 10, 2016

    @mattleibow
    ContributorAuthor

    I fixed this in 7d7e974

    Typically a canvas is owned by the object that provided it, for example a surface, picture recorder or document. But in one special situation, it can be constructed from a bitmap.

  4. ghost locked as resolved and limited conversation to collaborators on Aug 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions