I'm really need help! I can't understand how to work with prefabs and unloading.
I have the next situation.
I run my application on IPad from Xcode. Unity version 4.3.1 Pro. Watch memory using with: Xcode Debug Navigator Xcode Instruments Unity Profiler
I do next steps:
0) Unity starts from Empty scene.
Used memory XCODE Debug Navigator: 11 mb Instruments: 26.4 mb Unity Profiler: used total 13.2 reserved total 13.7
1) Load prefab from Resources folder
prefab = Resources.Load("Room1");
Used memory XCODE Debug Navigator: 30.8 mb Instruments: 49.54 mb Unity Profiler: used total 19.8 reserved total 20.4
2) Instantiate prefab
go = (GameObject)Instantiate(prefab);
go.name = "Room1";
XCODE Debug Navigator: 31.2 mb Instruments: 50 mb Unity Profiler: used total 20 reserved total 20.7
3) Destroy all objects on scene - memory not changed
Transform[] tr = FindObjectsOfType<Transform>();
for (int i = 0; i < tr.Length; i++)
{
GameObject goo = tr.gameObject;
if (goo.name != "Main Camera")
{
Destroy(goo);
goo = null;
}
}
XCODE Debug Navigator: 31.1 mb Instruments: 49.93 mb Unity Profiler: used total 19.8 reserved total 20.4
4) Call Resources.UnloadUnusedAssets();
- memory not changed
5) Call System.GC.Collect();
- memory not changed
6) Call UnloadAsset of prefab Resources.UnloadAsset(prefab);
- memory not changed
7) Call Resources.UnloadUnusedAssets();
- memory partially cleaned
XCODE Debug Navigator: 21.9 mb Instruments: 40.79 mb Unity Profiler: used total 13.2 reserved total 13.9
In profiler i see, that deleted all texures, that used in prefab
8) System.GC.Collect();
- memory not changed
9) Load empty scene - memory not changed
Here is another interesting moment:
When application goes to background and i start another application, size of used RAM greatly decreases, and when i call unity app - memory goes to first size with empty scene.
I have next questions:
1) Why memory not cleaned fully after delete prefab and call UnloadUnusedAssets - we can see it in Instruments and Xcode - but in Profiler we see, that memory practically fully free?
2) It's real to clean memory to initial size?
3) Do i all steps right or i do something wrong?
You can download test project here: http://gfile.ru/aa5on
Big thanks for your replies.