Skip to content

DrawTextProcessor memory leak from TessellatedMultipolygon  #215

@br3aker

Description

@br3aker

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp.Drawing
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

Description

DrawTextProcessor leads to memory leaks, well, not actual leaks but undisposed memory buffers.
Actual chain of 'responsibility': DrawTextProcessor -> PolygonScanner -> TessellatedMultipolygon

TessellatedMultipolygon is allocated and used by PolygonScanner here:

public static PolygonScanner Create(
IPath polygon,
int minY,
int maxY,
int subsampling,
IntersectionRule intersectionRule,
MemoryAllocator allocator)
{
var multipolygon = TessellatedMultipolygon.Create(polygon, allocator);
var edges = ScanEdgeCollection.Create(multipolygon, allocator, subsampling);
var scanner = new PolygonScanner(edges, multipolygon.TotalVertexCount * 2, minY, maxY, subsampling, intersectionRule, allocator);
scanner.Init();
return scanner;
}

It's also allocated here:

public static ScanEdgeCollection Create(
IPath polygon,
MemoryAllocator allocator,
int subsampling)
{
TessellatedMultipolygon multipolygon = TessellatedMultipolygon.Create(polygon, allocator);
return Create(multipolygon, allocator, subsampling);
}

Both cases are used to create ScanEdgeCollection which does not use it after Create method so we hopefully can safely add using statement for both cases and call it a day.

Steps to Reproduce

See SixLabors/ImageSharp#2079

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions