How do resources such as AnimationClips get garbage collected?

I have a GameObject with an Animation component attached to it. I load some AnimationClips into it (via Resources.Load).
I then Destroy this GameObject and create a new one. Similarly I attach an Animation component to it and load some AnimationClips.

I was expecting this sequence to have constant memory bounds but in fact each time the GO is destroyed and recreated I get another 10Mb added to the AnimationClips (according to Unity’s profiler) and shortly afterwards my app is killed by iOS after a memory warning.

What must I do to force the memory from the AnimationClips to be reclaimed? I had assumed that destroying the GO would do the job (or the Animation component). I’ve also tried caching the clips and destroying them explicitly but Unity prevents that due to “possible data loss”. As far as I can tell I have no other references to the original GO or the clips that would prevent the GC from collecting them.

You should probably try calling Resources.UnloadUnusedAssets http://unity3d.com/support/documentation/ScriptReference/Resources.UnloadUnusedAssets.html

Resources itself aren’t duplicated when using Resources.Load as far as i know. If you call Resources.Load on the same resource, it will return the same instance. The first time you use Load it will load the asset into memory. So the real assets aren’t duplicated.

However some assets are duplicated by the using component. For example a material that is assigned to the .material property of a renderer will create a duplicate and use that. When using sharedMaterial, no duplicates are generated.

Again, as far as i know AnimationClips are also shared between Animation components, but AnimationStates aren’t. Usually they should be collected after the owning component has been destroyed.

If you can reproduce the issue, create a small test project and file a bug report.