Community discussion forum

Circular Referencing to COM Objects

This is a comment thread discussing Circular Referencing to COM Objects
  • 9 years ago

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

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 6 years ago

    very interesting and usefull trick. (I should have thought about it myself)

  • 5 years ago

    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

  • 5 years ago

    Glad it helped.

  • 5 years ago

    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.

  • 5 years ago

    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.

  • 5 years ago

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

Post a reply

Enter your message below

Sign in or Join us (it's free).