Professional Web Applications Themes

killing scripts - Macromedia Director 3D

Hi All, If I add a script to a models userdata like so: myModel.userData.addProp(#pScript, new(script "myScript", me) will the script instance be completly deleted via calling reset world(). This is the only ref made to the script, so I asume it to be so, it looks like it does but checking just in case. Cheers, pop...

  1. #1

    Default killing scripts

    Hi All,

    If I add a script to a models userdata like so:
    myModel.userData.addProp(#pScript, new(script "myScript", me)

    will the script instance be completly deleted via calling reset world(). This
    is the only ref made to the script, so I asume it to be so, it looks like it
    does but checking just in case.

    Cheers, pop

    popgodabubble Guest

  2. #2

    Default Re: killing scripts

    It is very easy to create a memory leak by not properly disposing of pointers
    to instances or models before calling resetWorld(). In your case, maintaining
    a pointer to myModel at the point that resetWorld() is called will cause a
    memory leak.

    Try this test in the Message window. It assumes that you are aware of the
    following

    1) An instance reference indicates how many pointers there are to the given
    instance.
    Example: -- <offspring "" 2 734daf0> has 2 pointers to it, as shown by the
    2 after the
    string script name.
    2) When you use "put" for an instance in the Message window, the Message window
    creates a temporary pointer to the instance, thus giving a number of
    pointers 1 higher
    than what you might expect.
    3) To workaround this, you can add the instance to a list, and use put on the
    list.
    The Message window will create an additional temporary pointer to the list,
    but will
    now show the expected number of pointers for the instance.

    gMember = new(#shockwave3D)
    gModel = vMember.newModel("Plane", gMember.modelResource(1))

    gScript = new(#script)
    gScript.scriptText = "--" -- so it compiles
    gList = [script(gScript).new()]
    put gList
    -- [<offspring "" 1 82147c0>] -- 1 pointer to the instance on gList

    gModel.userData.addProp(#script, gList[1])
    put gList
    -- [<offspring "" 2 82147c0>] -- plus a pointer to the instanco on userData

    gMember.resetWorld()
    put gList
    -- [<offspring "" 2 82147c0>]

    -- There are still two pointers. Perhaps this is because gModel still holds a
    pointer to the now-deleted model, so its userData list still exists.

    gModel = VOID
    put gList
    -- [<offspring "" 2 82147c0>]

    As you can see, there are still two pointers: one on gList, and one which is
    now inaccessible. We have created a memory leak.

    In other words, you must be very careful to delete the instance from the
    userData list, or to delete all pointers to the userData list and the model it
    is attached to, before you use resetWorld() on the member. You should use
    either...

    gModel.userData.deleteAll() -- to delete the instance from the userData list
    OR
    gModel = VOID -- to delete the additional pointer to the model

    ... before you call gMember.resetWorld() .

    I strongly recommended that you write the code that disposes of an instances
    at the same time that you write the code to create it, and that you take care
    to dispose of all pointers in a logical order, so that none become orphaned and
    inaccessible.

    openspark Guest

  3. #3

    Default Re: killing scripts

    Hi, thanks for your reply, its just the info I was looking for.

    Upon implimentation of a script by adding it to userdata as detailed, with a
    ref stored as a list entry indicates 2 pointers within the script instance
    name.

    This sugguests that if there is no additional ref ( model self contained
    within w3d, not created) that if upon reseting the world the userdata is
    removed and thus also all referance to the script.

    Ill do a bit more testing, but for now have implimented via your suggestions
    and works great. I was not aware that put added a tempory ref, thanks loads for
    that info.

    Cheers for time and all, pop



    popgodabubble Guest

Similar Threads

  1. php variables are killing me
    By Sean McMurtrey in forum Macromedia Flash Data Integration
    Replies: 1
    Last Post: June 22nd, 02:07 PM
  2. OSX- the slowness is killing me
    By sly one webforumsuser@macromedia.com in forum Macromedia Fireworks
    Replies: 4
    Last Post: October 9th, 11:00 PM
  3. Killing IE via win32::ole ??
    By C. Martin in forum PERL Miscellaneous
    Replies: 0
    Last Post: July 25th, 10:54 PM
  4. HELP! BLOB is killing me
    By Kwan in forum Informix
    Replies: 1
    Last Post: July 18th, 05:15 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139