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.
Comments