-
Notifications
You must be signed in to change notification settings - Fork 668
NodeModel dispose on workspace close #15856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NodeModel dispose on workspace close #15856
Conversation
…se call to avoid reacting to events
…l on null or missing values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Improves workspace close performance by disposing nodes and unsubscribing connector events before connectors are deleted.
- Combines modification-event disabling and node disposal in
WorkspaceModel.Clear() - Introduces
ConnectorCollectionChangedevent and disposal logic inPortModelandNodeModel - Adds
Disposeoverrides inModelBase,NodeModel, andPortModelto clean up event subscriptions
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs | Moved node disposal into initial loop in Clear |
| src/DynamoCore/Graph/Nodes/PortModel.cs | Added connector‐collection event and Dispose |
| src/DynamoCore/Graph/Nodes/NodeModel.cs | Centralized port cleanup in DisposePort and Dispose override |
| src/DynamoCore/Graph/ModelBase.cs | Tracked disposal state with HasBeenDisposed |
| src/DynamoCore/Graph/Connectors/ConnectorModel.cs | Simplified null‐safe connector removal |
Files not reviewed (1)
- src/DynamoCore/PublicAPI.Unshipped.txt: Language not supported
Comments suppressed due to low confidence (2)
src/DynamoCore/Graph/Workspaces/WorkspaceModel.cs:1489
- After disposing each node, consider clearing the
Nodescollection (e.g.,Nodes.Clear()) to release references and prevent potential memory leaks.
foreach (NodeModel node in Nodes)
src/DynamoCore/Graph/Nodes/NodeModel.cs:1340
- [nitpick] The event name
ConnectorCollectionChanged(singular) and handlerConnectorsCollectionChanged(plural) are inconsistent. Consider renaming to one form (e.g.,ConnectorsCollectionChanged) for clarity.
p.ConnectorCollectionChanged += ConnectorsCollectionChanged;
| MarginThickness = new Thickness(0); | ||
| Height = Math.Abs(Height) < 0.001 ? Configurations.PortHeightInPixels : Height; | ||
| } | ||
|
|
Copilot
AI
May 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Add an XML doc comment for ConnectorCollectionChanged to explain when this event is raised and what subscribers should expect.
| /// <summary> | |
| /// Occurs when the collection of connectors associated with this port changes. | |
| /// </summary> | |
| /// <remarks> | |
| /// This event is triggered whenever a connector is added to or removed from the port's connector collection. | |
| /// Subscribers can use the event arguments to determine the nature of the change. | |
| /// </remarks> |
| } | ||
|
|
||
|
|
||
| public override void Dispose() |
Copilot
AI
May 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the Dispose override, invoke base.Dispose() after unsubscribing from InPorts/OutPorts and disposing ports to ensure cleanup completes before raising the Disposed event.
|
Closing this as the changes are merged in a different PR. |
Purpose
When a workspace is closed, a majority of the time is spent by nodes reacting to connector deletions. By unsubscribing from connector events before the a workspace closes, the time to get back to the main menu goes down substantially.
For the MaRS graph, this takes workspace close from about 8 to 4 seconds. For the Car_Configurator graph, this takes workspace close from about 2 minutes down to 40 seconds.
Performance
Old

New

Declarations
Check these if you believe they are true
*.resxfilesRelease Notes
N/A
Reviewers
@mjkkirschner
FYIs
@dimven