EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+

#Previous question #Index of COM/DCOM Questions #Next question


AddRef() function increments the reference count of the object. Release() function decrements the reference count of the object and when the life time expires or rather the reference count reaches zero, server deallocates the object.


The IUnknown::AddRef method increments the reference count for an interface on an object. It should be called for every new copy of a pointer to an interface on a given object.


ULONG AddRef(void);



Return Value

Returns an integer from 1 to n, the value of the new reference count. This information is meant to be used for diagnostic/testing purposes only, because, in certain situations, the value may be unstable.


Objects use a reference counting mechanism to ensure that the lifetime of the object includes the lifetime of references to it. Every COM object includes a 32 bit unsigned integer member variable for reference counting. Initial value of this reference count is zero. IUnknown::AddRef is called to stabilize a copy of an interface pointer and increments it by one. The updated value is returned. This is called by IUnknown::QueryInteface in server side and it can also be called when object is cloned as pointer. Reference count can have values from 1 to (2^31)-1. Reference count increment should be atomic in case of objects are handled in multi-threaded apartment.


Decrements the reference count for the calling interface on a object. If the reference count on the object falls to 0, the object is freed from memory.


ULONG Release(void);



Return Value

Returns the resulting value of the reference count, which is used for diagnostic/testing purposes only. If you need to know that resources have been freed, use an interface with higher-level semantics.


IUnknown::Release returns the current reference count and decrements the reference count of the object. Reference count decrement should be atomic if client is accessing multi-threaded apartment model. IUnknown::Release should be called by the client at the end when this object is no longer needed in the program. COM server deletes or frees the memory allocated by the object once this is called. Client should not call any interface function after this call.

You have viewed 1 page out of 66. Your COM/DCOM learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

# COM DCOM Interview Questions and Answers :: ALL Interview .com
# COM DCOM - COM DCOM Interview Questions
# COM interview questions | TechInterviews
# COM Interview Questions - CodeProject
# Com Dcom Interview Questions - Com and Dcom in Asp Net
# ATL Interview Questions and Answers :: ALL Interview .com
# ActiveX Interview Questions and Answers :: ALL Interview .com

* #1 webmaster Tue 29 Apr/2014 02:07:42(GMT)  Like 0 Unlike 0

Dear Users,

We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.


Your message goes here:

My Post:*
Secutiry Code: ******  *
Preview this compose before posting this in discussion forum.
  1. Use [Sxx] code to show smiles. Example [S02]
  2. Use [URL ], example [URL http://www.google.com/]
  3. To display code or un formatted text use [CODE] [/CODE]. Example: [CODE] printf("Hello world"); [/CODE]
 [S01]   [S02]   [S03]   [S04]   [S05]   [S06]   [S07]   [S08] 
 [S09]   [S10]   [S11]   [S12]   [S13]   [S14]   [S15]   [S16] 
 [S17]   [S18]   [S19]   [S20]   [S21]   [S22]   [S23]   [S24] 

Note: Only members are allowed, * fields are mandatory.