Circular Referencing to COM Objects

Introduction

As many of you may know, every time you use a object variable to reference an object, the COM reference count is incremented for that object, and that is something you can learn how to avoid in this tutorial. For those of you who don't know what I am talking about, let me explain.

Every COM object, such as a VB form, or a textbox, or an instance object of a VB class, or an instance object of a C++ class, etc., implements the IUnknown interface. An interface can be considered a personality of an object. All COM objects implements the IUnknown personality. This interface provides access to other interfaces and also keeps count of how many object variables are pointing to the object. Why this? Well, a COM object will not be unloaded from memory if there is a reference to it (general rule, but some other rules may apply, like Visibility). This is why is a good practice to always set object variables to Nothing while programming in Visual Basic: To make VB reduce the reference count.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are only two kinds of languages: the ones people complain about and the ones nobody uses” - Bjarne Stroustrup