I have exposed c# dll as .net serviced component (com+) . It is being consumed by an unmananged client (Unify Vision). I have deployed this component under component services.
I set the pool size to 5 and the creation time out to 2 minutes. I am running the com+ under server mode. and set the idle shutdown time to 3 minutes.
Everything is working fine but once the max pool size(5) is reached, the processes are staying alive without getting cleaned up. And due to this,if I try to creat one more object ,its failing and hanging.
It seems that objects are not getting released by the consumer. There are two methods _Destroy and Dispose exposed by this serviced component. Which one do I have to use for releasing the object once it is used. Also, will the object get released immediately after the call to these methods. Is there any way to find out how many references are there to the object?
Also, Do I need to use anything like JIT and setting the auto complete attribute?. I already tried this option though.
I am not sure whether the object is getting released back to the pool. How to track this?
Please help
Thanks sveerap
There are two methods _Destroy and Dispose exposed by this serviced component. Which one do I have to use for releasing the object once it is used.
Since you are dealing with a Server (out of process) Application the client should not have to call Dispose(). If your component is configured properly dispose will actually create/activate a new instance just to invoke the Dispose method. Read about Object Lifetimes in the article Understanding Enterprise Services (COM+) in .NET for a full picture.
will the object get released immediately after the call to these methods.
Yes, it will be returned to the pool.
Is there any way to find out how many references are there to the object?
Use the COM+ Explorer to view all components in your application. Set the view to status and you will get to see the number of objects, the number of activated objects, the number of pooled objects, and the call time.
Also, Do I need to use anything like JIT and setting the auto complete attribute?. I already tried this option though.
Yes, you will have to use JIT and call ContextUtil.DeactivateOnReturn = true;
.
I am not sure whether the object is getting released back to the pool. How to track this?
You can override the Activate and Deactivate methods to see when your component is removed from the pool and released back to the pool.
Here's an example that has a pool with a maximum number of 1 object but returns the instance to pool immediately after the method call:
using System;
using System.EnterpriseServices;
using System.Runtime.InteropServices;
namespace ClassLibrary1
{
[ComVisible(true)]
[EventTrackingEnabled(true)]
[JustInTimeActivation(true)]
[ObjectPooling(CreationTimeout=60000,
Enabled=true, MaxPoolSize=1, MinPoolSize=0)]
public class Class1 : ServicedComponent
{
public Class1()
{
}
public string Hello()
{
System.Diagnostics.Trace.TraceInformation("Call Hello");
// We are done after this call so return this instance to the pool
ContextUtil.DeactivateOnReturn = true;
return "world";
}
// Get an instance from the pool
protected override void Activate()
{
System.Diagnostics.Trace.TraceInformation("Activated");
base.Activate();
}
// Return an instance to the pool
protected override void Deactivate()
{
System.Diagnostics.Trace.TraceInformation("Deactivate");
base.Deactivate();
}
// Runtime will call Dispose after method call (with disposing = true)
protected override void Dispose(bool disposing)
{
System.Diagnostics.Trace.TraceInformation("Disposing = " + disposing);
base.Dispose(disposing);
}
}
}
If you call the Hello method concurrently by multiple clients without releasing the client objects you will see that the method does not block (except for the duration of the call) because the object is released back to the pool after the Hello method returns. Use DebugView to see the sequence of calls. Here are 2 clients calling concurrently with a sleep immediately after the call to Hello.
00000001 0.00036997 [6068] Activated
00000003 0.00160919 [6068] Call Hello
00000005 0.00493093 [6068] Deactivate
00000007 0.00567035 [6068] Disposing = True
00000009 0.14866389 [6068] Activated
00000011 0.14876986 [6068] Call Hello
00000013 0.14885986 [6068] Deactivate
00000015 0.14896829 [6068] Disposing = True