Skip to content

Managed memory leak on disconnect #3675

Open
@MDoerner

Description

@MDoerner

RD seems to have a managed memory leak on disconnect.

This can be observed as follows:

  1. Comment out the shutdown invokation in UIDispatcher.Shutdown(). (See UiDispatcher shutdown/restart problem causing Addin unload/reload to fail #3645 for why you should do this.)
  2. Add GC.Collect(); GC.WaitForPendingFinalizers() to the finally block of ShutdownAddIn in Extension. (This is nessesary since no finalizers will ever run until shutdown, provided you have enough memory.)
  3. Open RD in the debugger.
  4. Unload RD via the add-ins dialog.
  5. Reload RD via the add-in dialog.
  6. Close the host application.

In the debug output, you should be able to observe the following:

  • There are messages that the finalizers for the DockableToolwindowPresenters have run.
  • All but the one for SC get finalized right on disconnect (unload and shutdown).
  • Both SC presenters get finalized only on the final shutdown, and much later than anything else.
  • On reload, there are exceptions for the three commands OpenProjectPropertiesCommand, ImportCommand and ExportAllCommand stating that an RCW has already been disconnected from its target.

I investigated a bit further by adding addig finalizers for logging to some suspects that could hold the SC presenter alive. It seems that the presenter is kept alive by two commands, the CommitCommand and the UndoCommand, which are both kept alive by the CodeExplorerViewModel, I could find out yet what is keeping this alive.

That the CE is kept alive means that everything it references, beit directly or indirectly, is kept alive as well; that is half of RD.

The exceptions on the three commands seem to be connected. All three are referenced by the CE view model and their EvaluateCanExecute methods contain the accesses to the stale RCWs. Somehow, they still seem to react to some change notifications.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions