Description
RD seems to have a managed memory leak on disconnect.
This can be observed as follows:
- 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.) - Add
GC.Collect(); GC.WaitForPendingFinalizers()
to the finally block ofShutdownAddIn
inExtension
. (This is nessesary since no finalizers will ever run until shutdown, provided you have enough memory.) - Open RD in the debugger.
- Unload RD via the add-ins dialog.
- Reload RD via the add-in dialog.
- Close the host application.
In the debug output, you should be able to observe the following:
- There are messages that the finalizers for the
DockableToolwindowPresenter
s 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
andExportAllCommand
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.