Object Life Cycle Implications

There is a variety of ways to instantiate an object with COM, the typical way being to call CoCreateInstance. With COM, any function that activates an object will also initialize the reference count to one. When you are done with the object, you must remember to call Release on the object. When you decide to call Release is entirely up to you. In some cases, you will instantiate an object, call methods on one or more of its interfaces, and then immediately release the interface pointer. In other cases, you may instantiate your COM object when the application starts and hold the interface pointer until the application shuts down. In this latter model, you will likely use the same object again and again. Which approach ...

Get .NET and COM Interoperability Handbook, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.