title: MEF keeps reference of NonShared IDisposable parts, not allowing them to be collected by GC
body: <p>I've encountered somewhat of a problem in MEF's part lifetime which causes memory leaks in my Prism application.</p>
  
  <p>My application exports views and viewmodels with the <code>PartCreationPolicy</code> being set to <code>CreationPolicy.NonShared</code>. The views and viewmodels inherit from <code>ViewBase</code> and <code>ViewModelBase</code> respectively, which implements <code>IDisposable</code>.</p>
  
  <p>Now, since my parts implement <code>IDisposable</code>, a reference to them is kept by the container, which causes them to not be released by the garbage collector. According to <a href="http://mef.codeplex.com/wikipage?title=Parts%20Lifetime">MEF documentation on part lifetime</a>, this is by design:</p>
  
  <blockquote>
    <p>The container will not hold references to parts it creates unless one of the following is true:</p>
    
    <ul>
    <li>The part is marked as <code>Shared</code></li>
    <li>The part implements <code>IDisposable</code></li>
    <li>One or more imports is configured to allow recomposition</li>
    </ul>
  </blockquote>
  
  <p>How then can I make MEF not keep a reference to these parts? Is there an attribute I can use to let MEF know I don't want it to keep a reference to my part even if it implements <code>IDisposable</code>?</p>
  
  <p>Both of the strategies discussed in the above article don't seem like good solutions for me:</p>
  
  <ul>
  <li><code>ReleaseExport</code> requires an <code>Export</code> object as a parameter, which I don't know how to provide. I have the instance of my view, but there's no way for me to know what was the contract that was used to create the view. It would've been great if there was an overload for <code>ReleaseExport</code> which could receive any object created by the container.</li>
  <li>Using a child container doesn't seem like a natural option either.</li>
  </ul>
  
  <p>Any help will be greatly appreciated.</p>