We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

[2929] Circular Referencing to COM Objects

Last post 02-21-2003 3:52 AM by ZanalKhan. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 01-01-1999 12:00 AM

    [2929] Circular Referencing to COM Objects

    This thread is for discussions of Circular Referencing to COM Objects.

    • Post Points: 0
  • 10-10-2002 5:44 PM In reply to

    good article

    very interesting and usefull trick. (I should have thought about it myself)
    • Post Points: 0
  • 12-10-2002 6:47 AM In reply to

    • igitur
    • Not Ranked
    • Joined on 12-10-2002
    • New Member
    • Points 10

    excellent

    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.  Everything going smoothly again.

    igitur
    • Post Points: 0
  • 12-20-2002 12:50 PM In reply to

    • webjose
    • Top 10 Contributor
    • Joined on 01-02-2002
    • Guru
    • Points 11,015

    No problem

    Glad it helped.
    • Post Points: 0
  • 01-20-2003 12:06 PM In reply to

    How About Reducing the Reference Count?

    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 a browser, it causes an error report and the browser stays in memory.
    I realize that setting the controls reference to Nothing during the Usercontrol_Terminate event would solve the problem, but your article explains why this was not happening. So that is good.
    Your solution is intriguing, but I would like to ask you if another solution might work.
    How about we reduce the refrence count on the objects in the Initialize routine? Like this:

    Private Sub UserControl_Initialize()
       Set Splitter1.LeftCtl = LeftThing
       Set Splitter1.RightCtl = RightThing

       ReduceRefrenceCountByOne LeftThing
       ReduceRefrenceCountByOne RightThing
    End Sub

    Now the Controls will be come out of memory as we really want when the parent control terminates. Incidentally, their UserControl_Terminate events will fire correctly too.

    Perhaps you have written the code to do the evil reference count manipulation?

    What do you think?

    G.
    • Post Points: 0
  • 02-09-2003 5:05 AM In reply to

    • webjose
    • Top 10 Contributor
    • Joined on 01-02-2002
    • Guru
    • Points 11,015

    Yes, can be done

    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 by creating or using a type library that does define the IUknown interface.  Then you could just do something like this:
    Code:
    Private Sub UserControl_Initialize()

    dim oObject as IUnknown

      Set Splitter1.LeftCtl = LeftThing
      Set Splitter1.RightCtl = RightThing

      set oObject = LeftThing
      oObject.Release
      set oObject = Nothing
      set oObject = RightThing
      oObject.Release
      set oObject = Nothing
    End Sub

    That should take care of it.  However, this method is somewhat cumbersome and can be easily avoided by soft referencing.  I say go with soft referencing.
    • Post Points: 0
  • 02-21-2003 3:52 AM In reply to

    Great Tutorial!!(Previous &this)

    Great tutorial.This will definitely change the way i look up on these Matters..
    • Post Points: 0
Page 1 of 1 (7 items)