Repository navigation
Closed
Labels
Description
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
DEBUGandRELEASEmode - 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:
ImageSharp.Drawing/src/ImageSharp.Drawing/Shapes/Rasterization/PolygonScanner.cs
Lines 93 to 106 in 241891b
| 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:
ImageSharp.Drawing/src/ImageSharp.Drawing/Shapes/Rasterization/ScanEdgeCollection.cs
Lines 38 to 45 in 241891b
| 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
Reacted by Brian Popow
Activity
JimBobSquarePants commentedon Apr 9, 2022
Yep. That looks sensible. I'll run some tests later.
Thinking in the open, we should probably add an assertation in all our tests at some point.
tocsoft commentedon Apr 10, 2022
should be covered/do able using the proposed helpers from #216 (which includes a fix for this issue)