Professional Web Applications Themes

Memory leak with deleteModel - Macromedia Director 3D

Hi Guys, I'm deep Cloning and deleting models on the fly. I delete all the modifier, textures, shaders and model resources associated with the model, then delete the model itself. However, the memory inspector is saying I'm gaining 1 or 2 K after each deepClone/delete performed. What else do I need to delete ? Like a "DeepDelete" would perform ? Has anyone else had this trouble ? The object being cloned contains bones and bonesPlayer by the way. Rix...

  1. #1

    Default Memory leak with deleteModel

    Hi Guys,

    I'm deep Cloning and deleting models on the fly.

    I delete all the modifier, textures, shaders and model resources associated with the model, then delete the model itself.

    However, the memory inspector is saying I'm gaining 1 or 2 K after each deepClone/delete performed.

    What else do I need to delete ? Like a "DeepDelete" would perform ? Has anyone else had this trouble ?

    The object being cloned contains bones and bonesPlayer by the way.

    Rix




    Rix webforumsuser@macromedia.com Guest

  2. #2

    Default Re: Memory leak with deleteModel

    I found this on the Dir3D-l newsgroup. . . Bad news. . .

    "it is a leak,
    but not a serious bug (actually it is not so much,memory, unless you
    create several thousands of names)
    yes, the xtra somewhere stores the names you used for objects and
    doesn't release the memory after deleting them.

    there is other such data 'remembered' even after deleting the object.
    for shaders for example names are stored along with some properties
    the shader had before it was deleted. "

    This is really annoying, I hope they fix it in the next version of shockwave3D.

    Rix


    Rix webforumsuser@macromedia.com Guest

  3. #3

    Default Re: Memory leak with deleteModel

    Are you sure deep cloning is really necessary? I found that recreating the models using your own code is faster even the normal cloning.

    Also, why on earth would you need to clone the model resource? Unless it's either a #particle system or maybe a custom #mesh primitive, it's useless, right?

    You can create your own cloning handler: that creates a new model, assigns it the same model resource, transform and shaderlist from the original model. If you are using cloneDeep to clone shaders, that's a WASTE. Make your own shader cloning handlers, it's much more reliable.

    Also, try to recycle names. It's likely that you'll have a maximum amount of clones in the scene at once. When creating new clones, assign them a pre-difinied name and append a incremental number to it. Then have that counter reset after getting past a certain limit.

    As example, let's say you are using clone to produce projectiles that die after some time. Based on the frequency the projectiles are shoot at, and how long they take to die, you can guess the max number of those in the scene at once (or you can simply guess a high number). Have a counter increment everytime you create one, and have it reset after getting past the maximum.

    Let's say you never have more than 50 projectiles at once. Have your counter go from 0 to 60, as example, then use that for projectile names: bullet0, bullet1, bullet2, bullet3... etc. When the counter reaches 60, reset it to 0. bullet0 should be already deleted by then, and you'll reuse it's name.


    Medion webforumsuser@macromedia.com Guest

  4. #4

    Default Re: Memory leak with deleteModel

    "Medion" [email]webforumsusermacromedia.com[/email] wrote:
    > Are you sure deep cloning is really necessary? I found that recreating the models using your own code is faster even the normal cloning.
    > You can create your own cloning handler: that creates a new model, assigns it the same model resource, transform and shaderlist from the original model.
    I also like to use that approach. Besides, you can also make a
    preloader bar, which is impossible when cloning one big model (I don´t
    like to freeze user´s screen).
    --
    Agustín María Rodríguez | [email]agustinOnWine.com.ar[/email] | [url]www.OnWine.com.ar[/url]

    Agustín María Rodríguez Guest

  5. #5

    Default Re: Memory leak with deleteModel

    Hi Medion,

    Don't get stressed, I'm not being as stupid as it appears ;)

    I am already using a numbered naming system.

    The models that need dynamically cloning and deleting have to be deepCloned because they contain bones. There is a problem with director where if you clone (not DeepClone) a boned object, directly alter the bones transforms, and use the modelUnderLoc() the mesh appears correctly BUT the modelUnderLoc() detects an invisible mesh as if the bones of the original and the cloned object are in the same positions and it's confusing the bones of the cloned object with the original !

    Any known workarounds ?

    The result of this is that the modelUnderLoc() "misses" the models mesh some times, and detects the "ghost" mesh other times.

    That is why I am using cloneDeep !

    Do you know which aspect of an imported object the bone data is attached to ? The resource or the modifier etc. ?

    Also I would like to have multiple objects with the same number of bones, and be able to "swap" the model Resources, but I can't get it working, probably due to a similar problem.

    Any ideas ?

    By the way, I'd like to take this opportunity to thank Medion for all the help he gives this news group. Does he really know everything ? :)

    Rix



    Rix webforumsuser@macromedia.com Guest

  6. #6

    Default Re: Memory leak with deleteModel

    "Rix" [email]webforumsusermacromedia.com[/email] wrote:
    > Any known workarounds ?
    Dirty workaround...but here we go:

    Using modelsUnderRay() in a scene that has models with the bonesPlayer
    modifier may produce a major slowdown (I´ve seen many people complaining
    about that... didn´t tried myself though).

    You may want to removeFromWorld() those models with bones, perform the
    modelsUnderRay() against dummie models (without #bonesPlayer) and then
    addToWorld() the models (or their referencies, which is faster:
    pGroupOfModels.addToWorld() instead of
    member("3D").model("biped").addToWorld()... the same when removing)
    > Do you know which aspect of an imported object the bone data is attached to ? The resource or the modifier etc. ?
    To the resource. It stores which vertices are affected by each bone. At
    least that´s what I´ve found in many tests I did IIRC.

    > Also I would like to have multiple objects with the same number of bones, and be able to "swap" the model Resources, but I can't get it working, probably due to a similar problem.
    You can´t apply the bonesPlayer modifier to a mesh that has not been
    exported from Max with the same bones structure. That s because I
    needed many times using bones with a mesh built with code....
    > By the way, I'd like to take this opportunity to thank Medion for all the help he gives this news group. Does he really know everything ? :)
    Nah.. he knows only what I taught him jaja.

    Cheers!
    --
    Agustín María Rodríguez | [email]agustinOnWine.com.ar[/email] | [url]www.OnWine.com.ar[/url]

    Agustín María Rodríguez Guest

  7. #7

    Default Re: Memory leak with deleteModel

    Nah, I don't know it all. That might be Noisecrime :P

    But one thing I know: avoid casting rays on models that contains bones as if your life were at stake! It's just horridly slow, prolly because the 3D engine has to update whatever kind of geometry cache it creates for ray intersection checks every time a modelsUnderRay/modelsUnderLoc is issued.

    Have some sort of bounding mesh to work as collision area for the model, and if you need limb accuracy, have models that align themselves to the bones' positions.

    Ah, and for using simplier, invisible models for raycasting (that can get some orders of times faster than casting it into the actual scene's geometry, depending on complexisit) do this:

    1) Create a group, call it "scene" or something. Put all models that should be visible in that group

    2) Create another group called "collision" or something. Put all bounding models in that group.

    3) Set group("collision").parent to VOID. This will make Director plain ignore all models in it, and not render them.

    Then, whenever you want to check for modelsUnderRay() or modelsUnderLoc(), do this:

    1) Set group("scene").parent to VOID

    2) Set group("collision").parent to member("3d").group[1]

    3) Do the raycasting

    4) Set group("scene").parent to member("3d").group[1]

    5) Set group("collision").parent to VOID


    Director only performs raycasting with models that are "in the world", I mean, that are have group("world") (group[1]) in the root of their hierarchy. So, removing the models you want to ignore, and placing back invisible models you want to check gives you a lot more control over the wholre proccess.

    Also doing this with a whole group at once is a billion times faster than setting the parent individually for every model.


    Medion webforumsuser@macromedia.com Guest

Similar Threads

  1. SQL Memory Leak
    By sudopong in forum Coldfusion Server Administration
    Replies: 0
    Last Post: January 15th, 01:57 AM
  2. #39438 [NEW]: Memory leak PHP Fatal error: Out of memory
    By nikolas dot hagelstein at gmail dot com in forum PHP Bugs
    Replies: 11
    Last Post: December 1st, 08:08 PM
  3. SQL Memory Leak
    By in forum Coldfusion Server Administration
    Replies: 0
    Last Post: September 6th, 06:15 PM
  4. memory problem/memory leak
    By Tron Juan Del Marco webforumsuser@macromedia.com in forum Macromedia Director Basics
    Replies: 1
    Last Post: January 20th, 06:02 PM
  5. Memory consumption of Ruby/mod_ruby combo on Apache [memory leak]
    By David Heinemeier Hansson in forum Ruby
    Replies: 4
    Last Post: September 10th, 01:58 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