Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug: Unity Not Releasing AnimationClips

Discussion in 'Editor & General Support' started by motionsmith, Mar 29, 2012.

  1. motionsmith

    motionsmith

    Joined:
    May 26, 2011
    Posts:
    12
    Hello,

    We have found what we believe to be a bug, and would like and wanted to report it, as well as possibly get advice for how to move forward.

    We've found that when AnimationClips are added to an object via script (AddClip()), they do not get garbage collected, even after the object is gone.

    We have reproduced this in the simplest project possible. The project creates and destroys instances of a cube object using two respective keys. You can see the simplicity of the project structure here.



    The cube is the prefab resource we are loading. The CubeScript simply attaches an animation to itself dynamically, like this:



    Finally, there is very simple code for creating/destroying the cube object.



    You can see that we have left no references behind, however the animation clip references continue to pile on, eventually crashing the machine (which is easier to do on our actual massive project).



    When cubes are destroyed, the number of AnimationClips does not decrement. Then, when a new cube is created, the number of AnimationClips continues to increment.

    It is also interesting to note that the AnimationClips are not shared even though they are all using the same AnimationClip. However, if we add the AnimationClip directly to the Animation component via the inspector, all the cubes in the scene share one single AnimationClip. Why can the AnimationClips be shared when placed in the inspector but not dynamically via code?

    We would like to know what the best work-around is for this. For our game, we have quite large RemotePlayer objects with many dozens of animations. The RemotePlayers join and leave regularly, causing a memory leak. Additionally, the RemotePlayers cannot share their AnimationClips, meaning that each RemotePlayer (or "Cube" in the project example above) adds AnimationClip memory to the project.

    Thanks for your help,
    Eric
     
  2. claudekennilol

    claudekennilol

    Joined:
    Feb 13, 2012
    Posts:
    5
    Seconded. I'm trying to find a way to get around this and just found this thread. Since it was recently reported, I'm just throwing in my $.02 to say this is not an isolated occurence.