Skip to content

Not register event handler for Dispatcher.ShutdownStarted event#2888

Merged
ke-yu merged 6 commits intoDynamoDS:masterfrom
ke-yu:remove_dispatcher_shutdown
Oct 30, 2014
Merged

Not register event handler for Dispatcher.ShutdownStarted event#2888
ke-yu merged 6 commits intoDynamoDS:masterfrom
ke-yu:remove_dispatcher_shutdown

Conversation

@ke-yu
Copy link
Contributor

@ke-yu ke-yu commented Oct 29, 2014

It is part of effort to fix memory leak issue on Revit...RevitDynamoModel is referenced by many objects, when looking at the reference retention path, Dispatcher is one if them.

Related pull requests:

As Dispatcher is associated with thread, it is sort of static object, registering event handler for Dispatcher.ShutdownStarted prohibits the view from being garbage collected even it is unloaded. Plus, Dispatcher.ShutdownStarted is only fired when Revit application is shut down, it doesn't make sense to do "unload" things in it. Replace them with Unloaded event.

Reviewers:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would have hoped this dynNoteView_Unloaded gets named OnNoteViewUnloaded, and dynNoteView_Loaded be named OnNoteViewLoaded. But then I think you didn't do that so as to keep the naming convention in the class, which if fair enough (I'd also move the Unloaded to after Loaded).

Same for dynWorkspaceView_Unloaded below, but please don't change just because I mentioned it, this is my personal opinion :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense. Let me update it. :-)

@benglin
Copy link
Contributor

benglin commented Oct 30, 2014

LGTM!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet you intended to remove this before pull request creation ;)

@benglin
Copy link
Contributor

benglin commented Oct 30, 2014

Again, minor comments that can optionally be done. Otherwise, LGTM!

@ikeough
Copy link
Contributor

ikeough commented Oct 30, 2014

This was my change originally. If memory serves, I added this because Unloaded was not being called for certain views, and ShutdownStarted was. I believe I got this idea here:

http://stackoverflow.com/questions/8908276/why-does-unloaded-event-of-window-do-not-fire-in-wpf

Re-reading this, it makes sense that ShutdownStarted wouldn't be called until Revit closes because the dispatcher belongs to the thread. Nonetheless, this was done originally because when Close is called on a window, as it is during one of our numerous ways of shutting down Dynamo, the Unloaded event is not fired. Some things have changed about the shutdown sequence so as long as you can verify that every way we shut down dynamo (by Exit, or by closing the window) that unloaded is fired, LGTM.

@ke-yu
Copy link
Contributor Author

ke-yu commented Oct 30, 2014

Yep, verified all these view unloaded event handlers are invoked when Dynamo is closed in Revit.

ke-yu added a commit that referenced this pull request Oct 30, 2014
Not register event handler for Dispatcher.ShutdownStarted event
@ke-yu ke-yu merged commit 5cd9a00 into DynamoDS:master Oct 30, 2014
@ke-yu ke-yu deleted the remove_dispatcher_shutdown branch October 30, 2014 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants