I apologize for not having the links but I collected this many years ago.
David McNiven Sep 15 1999, 12:00 am
Tony
I got them this way:
(setq *AcadObj* (vlax-get-Acad-Object)
*AcadDoc* (vla-get-ActiveDocument *AcadObj*)
*PrefCol* (vla-get-Preferences *AcadObj*)
*MenuCol* (vla-get-MenuGroups *AcadObj*)
*LayCol* (vla-get-Layers *AcadDoc*)
*LayoutCol* (vla-get-Layouts *AcadDoc*)
)
Dave Mc
Tony Tanzillo Sep 16 1999, 12:00 am
David - All of those collections are all part
of an aggregation, which generally means they
do not need to be explicitly released (using
vlax-release-object).
In other words, if you didn't explicitly create
the objects (in this case, AutoCAD is creating
them), then you shouldn't have to release them.
Of course, you could try (vlax-release-object)
on all of those VLA-Objects, and if you still
get the AV, that would categorically rule them
out as being the problem.
My guess is that its a bug in VLISP, but I can't
really tell you very much without seeing the
code.
One thing you might try is putting a few (princ)
calls in the file you're loading to see exactly
where it's failing.
===========================================
From: Tony Tanzillo
Date: Feb/26/00 - 22:39 (GMT)
Some COM objects are referenced-counted, and others are not. IOW, the
lifetime of a COM object is not necessarily always controlled by its
reference count. In those cases, and/or depending on how a COM object was
created, it may not destroy itself when all references to it are released.
This is the case with both AutoCAD's application and document objects. The
Application object represents ACAD.EXE The document object represents an
open drawing. When you release either of them and there are no more
references, they don't get 'destroyed' (e.g., the drawing doesn't close, and
AutoCAD does not terminate). The COM wrappers for each of them also do not
seem to be destroyed either, and you can verify this by watching your system
memory usage after using (vlax-release-object) on them. You need to
'explicitly release' (excuse me for paraphrasing myself), objects which you
explicitly create, and/or objects that destroy themselves when they're
released, but there is little point to doing that with these two particular
objects since it doesn't really have any effect. From what I can tell, other
AutoCAD objects which have COM 'wrappers' that are created by AutoCAD
on-demand (e.g., the first time you reference a drawing entity, only then
does AutoCAD create a COM wrapper for it), you can release them, and the
memory used by their COM wrappers will be released, but if your inteniton is
to work with those objects frequently, then it may be preferable to not
release them, so their COM wrappers remain in memory, and do not have to be
re-created again, the next time they're needed. In the previous thread where
I mentioned that you need to explicitly release objects, I was generally
referring to objects that you create, or those which are created for you by
another ActiveX object as part of an aggregation. These generaly include
objects created using (vla-getinterfaceobject). In that case, when you
explicil8y release the COM object, it will destroy itself provided there are
no other references to it, and if there are no other referenced COM objects
in the same DLL server that houses the released object, then the DLL server
will be unloaded.
No. Visual LISP might release them for you the next time
it performs a garbage collection, but releasing objects
might have side effects that your application may depend
on, which means that you should always release them when
you're done using them.
Another problem that occurs with AutoCAD entities, is that
certain actions taken by the user can invalidate the COM
wrapper for an entity (because the underlying object type
has changed). In order to get AutoCAD to create a new COM
wrapper that corresponds to the correct type of entity, it
must first release the existing one, so waiting for Visual
LISP to get around to doing that is not good.
Your variable is not 'empty' as Frank put it, because
'emtpy' only applies to variants, not objects.
A null interface pointer is equivalent to a VB object
variable assigned to Nothing.
You may be calling (vlax-release-object) more than once
on a given object. That's the only way the variable can
be cleared.
Try using this in place of (vlax-release-object):
(defun release-object (obj)
(if (not (vlax-object-released-p obj))
(vlax-release-object obj)
)
)
Luis Esquivel Sep 15 2003, 10:09 am
This have been an issue before to many times...
I just release those objects created via:
vlax-create-object
vlax-get-or-create-object
vla-getinterfaceobject
AutoCAD takes care of the others ones...
Tony Tanzillo Sep 15 2003, 3:10 pm
There can be problems if you are holding a pointer
to an entity whose type can be changed by an editing
command (e.g., break a circle changes it to an ARC),
so it doesn't hurt to release objects when you don't
need them any longer. Unfortunately, that practice can
turn Visual LISP code into spaghetti, especially if
cleanup/error handling are factored into the equation.
Tony Tanzillo Sep 15 2003, 5:40 pm
"Devin"
> If I have multiple pointers to an object and I release the object, is it
> released from all pointers?
Yes, releasing an object causes all variables that
reference the same vla-object to become disconnected
from the object:
Command: (setq e (vlax-ename->vla-object (entlast)))
#<VLA-OBJECT IAcadPViewport 02840914>
Command: (setq e2 e e3 e)
#<VLA-OBJECT IAcadPViewport 02840914>
Command: (vlax-release-object e)
0
Command: !e2
#<VLA-OBJECT 00000000>
Command: !e3
#<VLA-OBJECT 00000000>
Doug Broad Sep 15 2003, 5:40 pm
Both Tony and Luis are correct.
Tony shows a special case where all the symbols are bound to
the same pointer.
The same thing would not be true of the following
(setq e (car (entsel))
a (vlax-ename->vla-object e)
b (vlax-ename->vla-object e)
c (vlax-ename->vla-object e))
(vlax-release-object a)
2
!a
#<VLA-OBJECT 00000000>
!b
#<VLA-OBJECT IAcadLine 0182c454>
!c
#<VLA-OBJECT IAcadLine 0182c454>
(vlax-release-object b)
1
!b
#<VLA-OBJECT 00000000>
!c
#<VLA-OBJECT IAcadLine 0182c454>