winforms icon indicating copy to clipboard operation
winforms copied to clipboard

ToolStrip class and it's accessible object are leaking in memory

Open dkazennov opened this issue 2 years ago • 14 comments

.NET version

.NET Version: 7.0

Issue description

ToolStrip and it's accessible object are left in memory after the ToolStrip control instance was inspected with accessibility tool (like Accessibility Insights or Inspect) and the form with ToolStrip is closed, garbage is collected, but accessibility tool is still opened.

ToolStrip.AccessibilityObject ToolStripButton.ToolStripButtonAccessibleObject ToolStripMenuItem.ToolStripMenuItemAccessibleObject ToolStripSplitButton.ToolStripSplitButtonButton

image

Expected behavior:

Amount of the leaked objects should be minimized to the uncleanable static objects only.

Steps to reproduce

Create a parent form with two buttons: one will be opening a child form with the ToolStrip control and the other will collect the garbage. Press the second button to open the child form with ToolStrip. Start the Inspect tool. Select the ToolStrip components using the Inspect tool. Close the child form. Clear memory with the first button of the parent form. DON'T close the Inspect tool. Look for ToolStrip accessible objects left in memory (using WinDbg, or dotMemory, or another suitable tool).

dkazennov avatar Jul 05 '22 07:07 dkazennov

Retesting during development (with ToolStripForm from main WinformsContolsTest application).

image

Test results with the Narrator. image

dkazennov avatar Jul 06 '22 10:07 dkazennov

It appears that RestoreFocusMessageFilter holds ToolStrip and ToolStripAccessibleObject in memory. image

dkazennov avatar Jul 08 '22 11:07 dkazennov

Have found a simple way to leave no accessible objects or corresponding control class objects in the Heap.

Result with the Inspect: image

Result with the Narrator: image

UPD: It works for most cases, but some certain ToolStrip Item control makes objects stuck in memory.

dkazennov avatar Jul 10 '22 17:07 dkazennov

Retested the fix: image Inconsistent with CIT. Rebuilded the release dll's and requested retest on more time.

dkazennov avatar Jul 15 '22 16:07 dkazennov

Verified on .NET 7.0 test pass build: .NET 7.0.100-rc.1.22425.12, issue is not fix as below: image

Ashley-Li avatar Aug 29 '22 11:08 Ashley-Li

@dkazennov Do we need to reactivate this issue?

Olina-Zhang avatar Aug 30 '22 01:08 Olina-Zhang

@dkazennov - I had reverted some of the changes that seemed risky for NET7 (I think) so we need to revisit this fix.

Tanya-Solyanik avatar Aug 30 '22 03:08 Tanya-Solyanik

@dkazennov Do we need to reactivate this issue?

Yes I believe we need to reactivate this issue.

dkazennov avatar Aug 30 '22 06:08 dkazennov

@dkazennov - I had reverted some of the changes that seemed risky for NET7 (I think) so we need to revisit this fix.

Yes, thanks. Should we open this issue or create a new one? Should we fix in in NET8?

dkazennov avatar Aug 30 '22 06:08 dkazennov

@Ashley-Li could you please describe steps to reproduce this case?

dkazennov avatar Aug 30 '22 08:08 dkazennov

@dkazennov Focused on ToolStrip controls with items in Narrator, Accessibility Insight and Inspect, there still have toolStrip items memory leak. Please see below test result with Narrator: Repro steps: 1.Create a parent form with two buttons: one will be opening a child form with the ToolStrip control and the other will collect the garbage. 2. Press the second button to open the child form with ToolStrip. 3. Start project without debugging. 4. Attaching project to WinDbg and adding symbols folder. 5. Start the Narrator tool. 3. Automatic reading for the ToolStrip control using Narrator. 6. Close the child form. 7. Clear memory with the first button of the parent form. 8. Don't close the Narrator tool. 9. Look for ToolStrip accessible objects left in memory (using WinDbg).

https://user-images.githubusercontent.com/56664234/187402552-1d94c3a6-ba98-4285-ab9a-9508725f63ca.mp4

Ashley-Li avatar Aug 30 '22 09:08 Ashley-Li

@dkazennov - if repro steps are different now, feel free to open a new issue

Tanya-Solyanik avatar Aug 31 '22 05:08 Tanya-Solyanik

@Ashley-Li Hello, could you please open new issue?

dkazennov avatar Sep 01 '22 05:09 dkazennov

@dkazennov @Tanya-Solyanik Have filed a new issue :#7713

Ashley-Li avatar Sep 01 '22 09:09 Ashley-Li

I was digging through the backlog and found #4808, is that related to the AccessibleObjects? Should that issue be closed in favour of this one?

elachlan avatar Nov 08 '22 00:11 elachlan

Closing this issue because @Ashley-Li had verified these steps and opened a follow up issue (#7713).

Tanya-Solyanik avatar Nov 08 '22 01:11 Tanya-Solyanik