This project has moved and is read-only. For the latest updates, please go here.

mvc 3 controller releaseExport

Apr 5, 2011 at 9:16 AM
Edited Apr 5, 2011 at 9:19 AM

An Mvc3 controller implements IDisposable. If a controller is MEFized and exported, it should be non-shared. I understand that IDisposable and non-shared are a lethal combination conducive to a memory leak.

If my understanding is correct, I should call ReleaseExport() on the CompositionContainer to remove a controller.

If this is true, where and when should I call ReleaseExport() ?

Can anybody of authority set the record straight?

Apr 9, 2011 at 5:15 PM

How is the MEF'ized controller being constructed? Not knowing exactly which MEFControllerFactory you are using it is hard to say what if anything you need to do. Generally however you should only ever need to call ReleaseExport on something that you yourself directly pulls out of a CompositionContainer via GetExport*. 

So MEF will end up calling Dispose on an object created by it if ReleaseExport is called on the Export that was used to get the object (or it root object if it is a dependency of some other object), or when Dispose is called on the CompositionContainer itself. If neither of those too things happen then Dispose will not be called on your object.