dotnet / dotnet/wpf

InputScopeAttribute leaks on TextBox in WPF.

Open
#8,192 3 comments 0 reactions 0 assignees View on GitHub
:construction: work in progress Performance
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

_This issue has been moved from [a ticket on Developer Community](https://developercommunity.visualstudio.com/t/InputScopeAttribute-leaks-on-TextBox-in-/10365684)._

---
Version: .NET 4.5 (may be later)

I repeatedly enter and delete characters in a WPF TextBox.
It leaks a little memory.

I checked with CLRProfiler45.
The leaking object is InputScopeAttribute.
I close the window, but the InputScopeAttribute object count does not decrease.

I found the cause on referencesource.
TextStore is not decrementing the reference count of InputScopeAttribute.

[https://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Documents/TextStore.cs,2698](https://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/Windows/Documents/TextStore.cs,2698)

```
2700 attrval.val.data1.Value = Marshal.GetIUnknownForObject(obj);
2784 _preparedattributes.Add(attrval);

```

The TextStore gets the reference count of the InputScopeAttribute with Marshal.GetIUnknownForObject.

```
785 _preparedattributes.Clear();
2666 _preparedattributes.Clear();

```

But it’s not releasing the reference count with Marshal.Release.

---
### Original Comments

#### Feedback Bot on 5/17/2023, 02:09 PM:

(private comment, text removed)
#### Feedback Bot on 9/5/2023, 10:54 AM:

(private comment, text removed)

---
### Original Solutions
(no solutions)

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.