AzMan & memory consumption

Mar 22, 2013 at 12:20 PM
I looked at AzManAuthorizationProvider.cs file and noticed a few things :
  • AZROLESLib which is referenced is a COM library
  • COM object are not automatically GC'ed
  • Maybe some manual release are necessary :
    if (clientCtx != null)
    if (azApp != null)
    if (store != null)
Am I right ?
Also What is the meaning of VS2010 Reference Property :Embed Interop Types ?

Mar 24, 2013 at 6:30 AM
COM object are not automatically GC'ed
That's not entirely true. COM Objects in .NET are accessed via a proxy called a runtime callable wrapper (RCW). The RCW is managed non-deterministically using the normal rules for .NET lifetime management. When garbage collected, the RCW will release the referenced COM object. So, (theoretically) the objects won't leak but it's not known when they will be released.

However, frequently COM objects hold expensive resources which you want to release as soon as possible (deterministically) which is why you might want to call Marshal.ReleaseComObject(). So, your idea might be a good one. However, there can be some subtleties (cached objects, lifetimes, shared RCWs, etc.) in these scenarios and I'm not very familiar with the specific AzMan COM API to know if there could be some unintended consequences.

See Marshal.ReleaseComObject Considered Dangerous for one story of what can go wrong.

For Embed Interop Types see Walkthrough: Embedding Types from Managed Assemblies (C# and Visual Basic). Basically, type information is embedded in your assembly which allows loose coupling. The cited example is embedding Microsoft Office COM object types so that a component can work with different versions of Microsoft Office installed on different machines.

Randy Levy
Enterprise Library support engineer
Support How-to
Mar 25, 2013 at 7:59 AM
Thanks for the answer.
In AzRoleslib dll 2 identical types exist AzAuthorizationStore and AzAuthorizationStoreClass.
I suppose AzAuthorizationStoreClass is the managed version that doesn't need the Marshal.ReleaseComObject.