-
Notifications
You must be signed in to change notification settings - Fork 635
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
Reduce Dynamo ViewModel memory leak Part I #9993
Conversation
/// </summary> | ||
internal void Dispose() | ||
{ | ||
this.workspaceViewModel = null; |
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.
I think the cases where this needs to be done in c# are small in number, why do we need to do it here?
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.
I believe something here is preventing HomeworkspaceViewModel to be disposed, not sure if it is related to the readonly field or simply calling dispose, will give it another try tomorrow
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.
From the retention paths you captured screenshots of it looks like the DynamoView
is indirectly holding onto an instance of RunSettingsViewModel
that is in turn holding onto the HomeWorkspaceViewModel
. I think we should try and dispose off the HomeWorkspaceViewModel
from DynamoView
in that case, no?
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.
I believe DynamoView is a singleton as well as the RunSettingsControl. So we won't be able to know when to dispose specifically from the view, but we can do that when closing the currentWorkspace. WorkspaceRemoved event will be triggered and then Dispose() on HomeWorkspaceModel will be called, that's why I added the logic there.
Running Self CI, I think this PR is good for review. It does not address all the issues, but is a good step. |
@@ -81,12 +81,12 @@ public RunTypeItem(RunType runType) | |||
/// notifications as those notifications are raised when the value is set on the | |||
/// model. | |||
/// </summary> | |||
public class RunSettingsViewModel : NotificationObject | |||
public class RunSettingsViewModel : ViewModelBase |
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.
this is an API break.
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.
or - could be, we need to be very careful changing the base class of a public class.
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.
How do we find out? ViewModelBase implements NotificationObject
and IDisposal
so I believe doing this will not remove any public property, that's actually why I thought it is not API breaking. Same reason below.
@@ -89,7 +89,7 @@ public interface ISearchEntryViewModel : INotifyPropertyChanged, IDisposable | |||
ElementTypes ElementType { get; } | |||
} | |||
|
|||
public class NodeCategoryViewModel : NotificationObject, ISearchEntryViewModel | |||
public class NodeCategoryViewModel : ViewModelBase, ISearchEntryViewModel |
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.
same here. can this be accomplished without changing the base class by just adding more interfaces?
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.
you can check this doc:
https://stackoverflow.com/questions/1456785/a-definitive-guide-to-api-breaking-changes-in-net
and do some thought experiments or real experiments with extensions using that class before and after.
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.
public abstract class ViewModelBase : NotificationObject,IDisposable
I dont think switching out the baseclass here break API backward compatibility because it only adds two APIs
IsDebugBuild
and
Dispose
Updated screenshots and could be more useful for our discussion |
public ObservableCollection<Logging.NotificationMessage> Notifications { get; private set; } | ||
|
||
private ObservableCollection<Logging.NotificationMessage> notifications; | ||
public ObservableCollection<Logging.NotificationMessage> Notifications |
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.
so this is kind of argg - we need to implement INotifyPropertyChanged to have .net gc this collection?
Can we add a comment saying as much so that in a year we don't delete it all when we see it is unused 😄
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.
Only because the collection is binding to WPF UI, I can add comments
All Unit tests passing, Ready for review |
LGTM |
Please Note:
DynamoRevit
repo will need to be cherry-picked into all the DynamoRevit Release branches that Dynamo supports. Contributors will be responsible for cherry-picking their reviewed commits to the other branches after aLGTM
label is added to the PR.Purpose
This PR is an example of things need to be done to dispose object in correct order to avoid memory leak.
The following is a comparison using our sample Geometry - Solids as file open candidate.
Baseline -> 2.4.0
Memory Consumption Difference between Dynamo StartUp-> File Open Once -> File Open 10x
File Open Once
File Open 10x
After -> Release build of this branch (2.5.0)
Memory Consumption Difference between Dynamo StartUp-> File Open Once -> File Open 10x
File Open Once
File Open 10x
Declarations
Check these if you believe they are true
*.resx
filesReviewers
@DynamoDS/dynamo
FYIs