Author Topic: vlax-release-object  (Read 3398 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
vlax-release-object
« on: January 07, 2004, 06:49:50 PM »
Probably something that most people wouldnt care about.

I have seen some comment on this issue without a definative answer.
Despite some opinions :-
Calling (vlax-release-object) on a COM object does not destroy it, the COM object's reference count is just decremented . The COM object is destroyed only when its reference count reaches 0.

Draw your own conclusions from the following exercise :

;;; Try this in a drawing session that has been running for a while.
;;; The Results shown were during a debugging/testing session.
;;; Your results may differ.
;;; The integer returned from (vlax-release-object  ....) is the instance/reference count

Code: [Select]


Command: (setq objAcadApplication (vlax-get-acad-object))
#<VLA-OBJECT IAcadApplication 00a876d8>

Command: !objAcadApplication
#<VLA-OBJECT IAcadApplication 00a876d8>

Command: (vlax-release-object  objAcadApplication)
55

Command: !objAcadApplication
#<VLA-OBJECT 00000000>

Command: (repeat 100 (setq objAcadApplication (vlax-get-acad-object)))
#<VLA-OBJECT IAcadApplication 00a876d8>

Command: !objAcadApplication
#<VLA-OBJECT IAcadApplication 00a876d8>

Command: (vlax-release-object  objAcadApplication)
154

Command: !objAcadApplication
#<VLA-OBJECT 00000000>

Command: (repeat 100 (vlax-get-acad-object))
#<VLA-OBJECT IAcadApplication 00a876d8>

Command: (setq objAcadApplication (vlax-get-acad-object))
#<VLA-OBJECT IAcadApplication 00a876d8>

Command: !objAcadApplication
#<VLA-OBJECT IAcadApplication 00a876d8>

Command: (vlax-release-object  objAcadApplication)
254

Command: !objAcadApplication
#<VLA-OBJECT 00000000>

Command: (repeat 100 (setq obj_another_AcadApplication (vlax-get-acad-object)))
#<VLA-OBJECT IAcadApplication 00a876d8>

Command: (vlax-release-object  obj_another_AcadApplication)
353

Command: (gc)
nil

Command: (setq objAcadApplication (vlax-get-acad-object))
#<VLA-OBJECT IAcadApplication 00a876d8>

Command: (vlax-release-object  objAcadApplication)
50

Command: (setq objAcadApplication (vlax-get-acad-object))
#<VLA-OBJECT IAcadApplication 00a876d8>

Command: (vla-get-vbe objAcadApplication)
#<VLA-OBJECT VBE 08c12564>

Command: (vlax-release-object  objAcadApplication)
50

Command: (vla-get-vbe objAcadApplication)
; error: null interface pointer: #<VLA-OBJECT 00000000>
; reset after error

Command: *Cancel*

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

SMadsen

  • Guest
vlax-release-object
« Reply #1 on: January 08, 2004, 07:07:12 AM »
These are just wild thoughts without any support at all.
A reference to a pointer is in my mind a different thing than the pointer itself. There seems to be no doubt that the address pointer for the acad app is unchanged during your tests. And it shouldn't change, either (if you ran it in the same session).

I believe the reference you are reffering to is a pointer to a pointer (a.k.a. handle). In other words, when you are referencing an object at a specific address, you are creating a handle that points to the address of the object. That's the address that is shown, not the handle's address.

When releasing the object, you are destroying the handle and not the pointer - otherwise you would destroy the object itself.
That's the reason you should never return a released reference. It's not because the object you are returning will be destroyed - it never is - but because the reference will be released.

The numbers in the test almost seems logical. 55-1+100 = 154 is fine, but I don't get the last count because you're creating 101 references and it returns 254? Hmmm.

SMadsen

  • Guest
vlax-release-object
« Reply #2 on: January 08, 2004, 07:10:14 AM »
Oh, I get it now. Releasing is decrementing 1 so 154+101-1 = 254.

By the way, the statement "The COM object is destroyed only when its reference count reaches 0" has no real impact on our "macrowise" access to objects belonging to a running thread.
Normally a pointer is up for release by the system if it is not referenced but as long as you can't specifically get hold of all references to e.g. the AutoCAD object, you won't experience a 0 reference count.