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

WCF service and MEF created instances lifetime

Aug 25, 2015 at 11:15 AM
I have a WCF service class that is requested periodically from UI data it should retrieve.
In the service class I import usually shared parts (they are used by other WCF services and expensive to create)

On the WCF service class, in it's constructor we do on the application unique catalog we have Container.ComposeParts(instanceOftheWCFService)

The thing is, the service class instance constructor gets called periodically/makes calls to Container.ComposeParts periodically.

We are using MEF from .NET framework 4 and when I dump process memory I see all the instances of the WCF service class laying around, "leaking".

Qustion: When one does ComposeParts could MEF hold on to the instance created that imports shared parts. The class itself (WCF service) does not have any attributes from MEF, so MEF should not hold any references to it...
Aug 25, 2015 at 1:49 PM
Just wanted to give more details. Looking for gc roots for one of the many service instances created I indeed confirm that a reference is being held to my service class:
!mroot 0000000006e9c660 
AppDomain 00000000006a4440: GCHandle(?) @ 000000001c0baf08