Problem with Clearing nodes from Part Manager


I have a problem that my diagram is in a tab control and when i move to another tab the OnUnloaded function in the diagram called and clears the nodes from the part manager and becuase of that when i return from the other tab i can’t change the selection in the diagram becuase the nodes don’t exist yet. i know i can set the UnloadingClearsPartManager to false but when i close the tab containing the diagram i want to clear everything so i won’t have memory leaks.

can you tell me how to solve this?
i am using the goWPF DLL


Is the problem only that selection seems to be lost when changing tabs?

I guess the issue is whether or not the Diagram realizes it’s inside a TabControl.
If you’re not using the standard TabControl, you might need to set UnloadingClearsPartManager to false in order to keep all of the state in memory when switching tabs.

So if you have done this, are you sure that there are memory leaks? If so, what actions and references are causing them? Do you make sure that for any place where you add an event handler you have code to remove them at the appropriate time?

the problem isn’t that we lost selection but we have tab that represend nodes in the digram and we want that when the user open a tab that represent a node in the digram then when we will switch to the tab with the digram the node that belong to tab we swicthed from will be selected.

i am not sure we will have memory leak becuase i added a dispose function to the class the hold the digarm that clears all kind of things including the nodes from the part manager of the diagram.
but i don't know if this can cause any problems becuase the OnUnload function do more then just cleaning the nodes from the part manager.
do you think there can be a problem if i set the UnloadingClearsPartManager to false?

That sounds like it has nothing to do with losing transient state between tabs.
So I wouldn’t set UnloadingClearsPartManager to false unless you really need to.

Instead, the problem is that the Node doesn’t exist yet for you to select it.
If the Node doesn’t exist yet, use a Diagram.InitialLayoutCompleted event handler to do that work. It will get called after the diagram’s model has been loaded and there’s been an initial layout. That’s also when you can call Diagram.Panel.CenterPart(node) to scroll the view to make the selected node visible.

the nodes exists when i switch tabs from the digram tab to another tab the UnLoad functions are being called and the part manager clear all the nodes in it. then when i go between tabs when i go to the tab with the digram i call to select the node according to the tab i was last but the part manager have no nodes becuase he clear them.

the FindNodeForData return null becuase of that. if i change the UnloadingClearsPartManager to false then i don't have the problem becuase the the part manager don't clear them and FindNodeForData don't return null.
do you think its ok to set the UnloadingClearsPartManager to false? if not can you create a fix with the logic of the UnLoad function public so i could call it when i close the diagram.

Oh, OK, I thought that you wanted to create a new diagram and select a particular node. So if the diagram existed before, then the clearing of the PartManager makes sense. And that implies you’re not using a regular TabControl either. So go ahead and set UnloadingClearsPartManager to false.

There shouldn’t be a memory leak if you aren’t dynamically creating and replacing tabs with Diagrams in them, assuming there aren’t other causes for retained memory.