Releasing an object...

Discussion in 'AutoCAD' started by Devin, Sep 15, 2003.

  1. Devin

    Devin Guest

    Am I supposed to be releasing active x objects after I access them through
    vla functions? I'm getting crashes occurring and was wondering how to
    handle objects properly. I also saw the function vlax-release-object and
    was unsure actually what it does.

    Thanks for any help,

    Devin
     
    Devin, Sep 15, 2003
    #1
  2. Devin

    Devin Guest

    Thanks for clarifying that for me.
     
    Devin, Sep 15, 2003
    #2
  3. 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
    #3
  4. Devin

    Devin Guest

    It can make it hard, especially if you want to return an object at the end
    of a function.

    Thanks,

    Devin
     
    Devin, Sep 15, 2003
    #4
  5. Devin

    Devin Guest

    If I have multiple pointers to an object and I release the object, is it
    released from all pointers?

    TIA,

    Devin
     
    Devin, Sep 15, 2003
    #5
  6. 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>
     
    Tony Tanzillo, Sep 16, 2003
    #6
  7. Devin

    Doug Broad Guest

    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>

    ETC.
     
    Doug Broad, Sep 16, 2003
    #7
  8. Devin

    Devin Guest

    I was just wondering how the release mechanism works. Thanks for your guys
    help!

    Devin
     
    Devin, Sep 16, 2003
    #8
  9. Devin

    Dan Allen Guest

    Is the problem just holding the pointer in a variable or using the pointer
    after the entity has changed?

    Dan
     
    Dan Allen, Sep 16, 2003
    #9
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.