Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 24,398 times

Contents

Related Categories

Circular Referencing to COM Objects - Introduction

webjose

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.

This code is for everyone's use and, although I have tested it the best I can, I cannot be held responsible for its use or misuse, or for any other type of damage WHATSOEVER. Use this code at your own risk. If you find an error or can improve it, feel

Comments

  • Great Tutorial!!(Previous &this)

    Posted by ZanalKhan on 21 Feb 2003

    Great tutorial.This will definitely change the way i look up on these Matters..

  • Yes, can be done

    Posted by webjose on 09 Feb 2003

    There is no secret as to how you decrease the reference count of a COM object. All you have to do is call the Release method of the IUnknown interface. But VB will hide this. However, you can cheat...

  • How About Reducing the Reference Count?

    Posted by GrahamEpps on 20 Jan 2003

    I have a project with Splitter controls that require references to pairs of controls that are proportionally resized by the user.
    The application GPF's (occasionally) upon termination. If run inside...

  • No problem

    Posted by webjose on 20 Dec 2002

    Glad it helped.:cool:

  • excellent

    Posted by igitur on 10 Dec 2002

    I struggled for a long time with my app hanging after it quits. It turned out to be a circular reference in the (approximately) 180 000 objects.

    Thnx for the great explanation and work-around. Ev...