WPF Stroke may memory leak
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
* .NET Core Version: All
* Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
**Problem description:**
Using DrawingAttributes referenced by other Strokes to create a Stroke object may cause memory leaks.
Step:
1. Strongly reference a Stroke object named AStroke
2. Using the AStroke.DrawingAttributes to create other Stroke object named BStroke. And we do not any object reference BStroke object
**Actual behavior:**
Before the AStroke is released, the BStroke object will never be released.
**Expected behavior:**
The BStroke object can free
**Minimal repro:**
https://github.com/lindexi/lindexi_gd/tree/11e830a5/KemjawyecawDurbahelal
**Reason**
In the constructor of the Stroke object, events of the DrawingAttributes object will be monitored, so the Stroke object will be strongly referenced by the DrawingAttributes
```csharp
internal Stroke(StylusPointCollection stylusPoints, DrawingAttributes drawingAttributes, ExtendedPropertyCollection extendedProperties)
{
_drawingAttributes = drawingAttributes;
_drawingAttributes.AttributeChanged += new PropertyDataChangedEventHandler(DrawingAttributes_Changed);
}
```
But the DrawingAttributes object is the attribute of the Stroke object, so the DrawingAttributes object is strongly referenced by the Stroke object
If all Stroke objects use the same DrawingAttributes object, then all Stroke objects will not be free if any Stroke object is not free
Contributor guide
Assessment
This issue has not been assessed yet.