winforms
winforms copied to clipboard
ToolStrip class and it's accessible object are leaking in memory
.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
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).
Retesting during development (with ToolStripForm from main WinformsContolsTest application).
Test results with the Narrator.
It appears that RestoreFocusMessageFilter holds ToolStrip and ToolStripAccessibleObject in memory.
Have found a simple way to leave no accessible objects or corresponding control class objects in the Heap.
Result with the Inspect:
Result with the Narrator:
UPD: It works for most cases, but some certain ToolStrip Item control makes objects stuck in memory.
Retested the fix:
Inconsistent with CIT. Rebuilded the release dll's and requested retest on more time.
Verified on .NET 7.0 test pass build: .NET 7.0.100-rc.1.22425.12, issue is not fix as below:
@dkazennov Do we need to reactivate this issue?
@dkazennov - I had reverted some of the changes that seemed risky for NET7 (I think) so we need to revisit this fix.
@dkazennov Do we need to reactivate this issue?
Yes I believe we need to reactivate this issue.
@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?
@Ashley-Li could you please describe steps to reproduce this case?
@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
@dkazennov - if repro steps are different now, feel free to open a new issue
@Ashley-Li Hello, could you please open new issue?
@dkazennov @Tanya-Solyanik Have filed a new issue :#7713
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?
Closing this issue because @Ashley-Li had verified these steps and opened a follow up issue (#7713).