-
Freeing Resources
HI,
Because Com+ will take care all resources when we call
SetComplete of Object Context, do you think we still need
to set all our object to nothing after use it ?
Based on acrticle i've read, COM+/MTS will only deactivated
object and willl activated it again when we call the same object.
What do you think ?
-
hi,
(sorry, my english is not very well)
first of all, the vb runtime has it's own garbage collector to freeing memory.
even if u don't explicitly set objects to Nothing, vb take care to reclaim memory when objects goes out of they scope.
activate/deactivate issue depend on the JIT service of COM+ and the SetComplete/SetAbort fucntions.
when u mark the "Enable JIT" option on your component, COM+ will use JIT only if u have a live reference to that object.
if u have a variable referencing that object in a function scope, the object memory will actually reclaim when the fucntion will over, and not deactivate, because the reference is temporary (function level).
but if u have, let's say, a global reference to the object (module level), the object will remain alive until u call explicitly SetComplete/SetAbort to it, only then the object will deactivate, and u will get a proxy. if u will reference to the object through your variable COM+ quickly, will activate that object and bring it to live.
u can see it the usage of the object in the Component Services panel (MMC).
when the object is alive u can see it's instance number at the Objects column, if u have a function level variable, as soon as the function get over u will see 0 Objects, and 0 Activate.
if u have a global variable and not have call yet SetComplete/SetAbort u will see N Objects (depend on the number of the instances) and N Activated. when u will call SetComplete/SetAbort, the Objects will remain N (because u have a real reference to it), and 0 Activated (because COM+ uses JIT to deactivate the object).
COM+ intend for middle tier business objects in a distributed application, hence, it is not reccomend to hold a live reference to the objects, but only a function level reference.
if u have distributed application with web UI, u definitely will not hold a live reference because u will create your business objects from an ASP page that is temporary inherently.
when u call SetComplete/SetAbort u actually update a flag variable called Done Bit, and depend on that flag COM+ decide weather to deactivate the object.
it is very important to know that because if u r using COM+ transaction, JIT is automatically checked on the component (when u mark Transaction Required/Supported).
COM+ will actually reclaim the memory of the objects participating in the transaction only if u called explicitly SetComplete/SetAbort or when the function that initiate the transaction get over.
but it is important to free resources as soon as possible, and to have as most shorter transaction because DTC transaction r very expensive, that's why it is important to call SetComplete/SetAbort as soon as u have done with the transaction.
-
Hi,
I am asking such question because I am on my work
creating Distribute application using Com+.
Thanks a lot for your infomartion.