dotnet / dotnet/wpf

WPF Stroke may memory leak

Open
#4,100 1 comment 2 reactions 0 assignees View on GitHub
.NET Framework Bug Performance
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.