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

0 Members and 1 Guest are viewing this topic.

QuestionEverything

  • Guest
vlax-release-object
« on: November 12, 2016, 03:52:07 PM »
Hello everybody,
This code is not mine:
Code: [Select]
(defun c:ATxt (/ VlaObjLine LinAngle VlaObjText )
(vl-load-com )
(setq VlaObjLine (vlax-ename->vla-object (car (entsel "\nSelect line: " ))) )
(setq LinAngle (vla-get-Angle VlaObjLine ) )
(while (setq VlaObjText (vlax-ename->vla-object (car (entsel "\nSelect text : " ))))
(vla-put-Rotation VlaObjText LinAngle )
(vlax-release-object VlaObjText )
)
(vlax-release-object VlaObjLine )
(princ)
)
I wanted to ask why "vlax-release-object" is used, and is this is necessary?

Usually I've seen it used like this:
Code: [Select]
(setq Obj (vlax-get-or-create-object "WScript.Shell"))
; do something
(vlax-release-object Obj)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: vlax-release-object
« Reply #1 on: November 12, 2016, 04:13:27 PM »
There is no firm documentation, but it is generally only considered necessary to release objects outside of the scope of the AutoCAD Object Model - there are many similar threads which discuss this.

QuestionEverything

  • Guest
Re: vlax-release-object
« Reply #2 on: November 12, 2016, 05:11:36 PM »
I just found some good thread about this, still makes no sence for me for being used in that code.

After not carefully reading it now I know that:

(vlax-release-object) destroys the pointer of the object, It doesn’t destroy the "object" but the memory for that object.
Used (vlax-dump-object), after that (vlax-release-object), and then (vlax-dump-object) again:
Code: [Select]
_$ (setq e (car (entsel)))
<Entity name: 7ff666a073a0>
_$ (setq o (vlax-ename->vla-object e))
#<VLA-OBJECT IAcadCircle 00000064758ab718>
_$ o
#<VLA-OBJECT IAcadCircle 00000064758ab718>
_$ (vlax-dump-object o)
; IAcadCircle: AutoCAD Circle Interface
; Property values:
...
T
_$ (vlax-release-object o)
0
_$ o
#<VLA-OBJECT 0000000000000000>
_$ (vlax-dump-object o)
; Object is not connected
nil
_$


tried the "inspect tool" after (vlax-release-object):
Code: [Select]
_$ o
#<VLA-OBJECT 0000000000000000>
_$

Error: null interface pointer: #<VLA-OBJECT 0000000000000000>
_1$
So the conclusion I did: is to "release" any object that is assigned as a local variable inside a function (after its use).
In order to free any pontentially used memory when the routine ends.
« Last Edit: November 13, 2016, 04:35:06 AM by QuestionEverything »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: vlax-release-object
« Reply #3 on: November 13, 2016, 07:24:35 AM »
So the conclusion I did: is to "release" any object that is assigned as a local variable inside a function (after its use).
In order to free any pontentially used memory when the routine ends.

Not absolutely necessary, as AutoCAD will perform its own garbage collection.

QuestionEverything

  • Guest
Re: vlax-release-object
« Reply #4 on: November 13, 2016, 08:19:01 AM »
Not absolutely necessary, as AutoCAD will perform its own garbage collection.
Hm okay, but is there any further action required? Like "empten the garbage" ?

Looks like its enough to follow this advice:
From what I have read and experienced, you only need to use the vlax-release-object on symbols that were set with vlax-get-object, vlax-create-object, vlax-get-or-create-object or with the method "getinterfaceobject".

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: vlax-release-object
« Reply #5 on: November 13, 2016, 08:38:05 AM »
Not absolutely necessary, as AutoCAD will perform its own garbage collection.
Hm okay, but is there any further action required? Like "empten the garbage" ?

You can force a garbage collection using the AutoLISP gc function, but it is my understanding that AutoCAD will automatically perform a garbage collection periodically.

Looks like its enough to follow this advice:
From what I have read and experienced, you only need to use the vlax-release-object on symbols that were set with vlax-get-object, vlax-create-object, vlax-get-or-create-object or with the method "getinterfaceobject".

Exactly - essentially as I noted earlier, it is generally only considered necessary to release objects outside of the scope of the AutoCAD Object Model.

QuestionEverything

  • Guest
Re: vlax-release-object
« Reply #6 on: November 13, 2016, 08:59:57 AM »
Thank you for helping,
This function is no longer mystery for me. :)