DynamoDS/Dynamo — pull request #2919 by ke-yu (2014-10-30 16:53:20+00:00)
Title: Fix memory leak: move reivt event handler from RevitDynamoModel to DynamoRevit

This is the last pull request for fixing [memory leak in Revit](http://adsk-oss.myjetbrains.com/youtrack/issue/MAGN-3404).

Other merged pull requests for fixing memory leak:
- [Not register event handler for Dispatcher.ShutdownStarted event] (https://github.com/DynamoDS/Dynamo/pull/2888)
- [Clear task queue when Scheduler is shutdown] (https://github.com/DynamoDS/Dynamo/pull/2881)
- [Inherit from NotificationObject to avoid memory leak in data binding] (https://github.com/DynamoDS/Dynamo/pull/2890)
- [Fix memory leak in NUnit - DynamoCoreTest](https://github.com/DynamoDS/Dynamo/pull/2859)

Memory leak in Revit is because Dynamo's root object ``RevitDynamoModel`` is still referenced from CLR's system objects or from Revit application's global object after it has been out of scope.

In Revit, although ``RevitDynamoModel`` properly unsubscribed Revit's application events (``DocumentOpening``, ``DocumentOpened``, ``DocumentClosed`` and ``ViewActivated``) when Dynamo is closed, the reference is not removed. Following reference retention paths are generated by dotMemory, it shows these event handlers are still referencing dead ``RevitDynamoModel`` instance:

![image001](https://cloud.githubusercontent.com/assets/2600379/4847562/ef828e24-6053-11e4-8a7a-ade5803379b0.png)

I wrote a test app which also proved these event handlers keep reference to the instance that ever subscribes one of these event, so in the pull request I move event handler from ``RevitDynamoModel`` to ``DynamoRevit``. The latter just calls the corresponding function in ``RevitDynamoModel`` when an event is fired.

Verified on Revit2015 with dotMemory that ``RevitDynamoModel`` is no longer leak.

Primary reviewers:
[ ] @ikeough
[ ] @pboyer