1
NGUI 3 Support / Atlas leaking when loaded from scene in asset bundles?
« on: February 26, 2015, 08:55:52 AM »
Hello,
Using memory profiler, attached to standalone Windows player, we see our main Atlas texture leaking every time we switch scenes. I have a feeling, the way we use them with asset bundles is the cause, but not sure.
The scenario is not that usual:
For the UI, we have 3 asset bundles containing several scenes with NGUI stuff in them - one bundle for each main state of the game - Login, Garage, Battle.
When game state changes, we load new 3D world using Application.LoadLevel, which cleans old gameobjects(UI stuff too) and does implicitly Resources.UnloadUnusedAssets. Then we load the UI scenes from the corresponding bundle, using LoadLevelAdditive, then we unload the bundle.
So you can imagine, the main atlas that is leaking, is present in each of these bundles (we are building them using BuildPipeline.PushAssetDependencies)
We already fixed couple of places that hold static references to NGui stuff, which we found using the profiler, but the atlas is still leaking - new instance appearing after each switch of game state.
For the leaked atlas texture, profiler now shows just 2 items in (Referenced By:) section:
UIAtlas
ManagedStaticReference
Drilling down these items shows nothing.
I managed to clean these leaked instances crudely by doing this after scene switch:
Any idea what could be causing this?
Thanks!
Using memory profiler, attached to standalone Windows player, we see our main Atlas texture leaking every time we switch scenes. I have a feeling, the way we use them with asset bundles is the cause, but not sure.
The scenario is not that usual:
For the UI, we have 3 asset bundles containing several scenes with NGUI stuff in them - one bundle for each main state of the game - Login, Garage, Battle.
When game state changes, we load new 3D world using Application.LoadLevel, which cleans old gameobjects(UI stuff too) and does implicitly Resources.UnloadUnusedAssets. Then we load the UI scenes from the corresponding bundle, using LoadLevelAdditive, then we unload the bundle.
So you can imagine, the main atlas that is leaking, is present in each of these bundles (we are building them using BuildPipeline.PushAssetDependencies)
We already fixed couple of places that hold static references to NGui stuff, which we found using the profiler, but the atlas is still leaking - new instance appearing after each switch of game state.
For the leaked atlas texture, profiler now shows just 2 items in (Referenced By:) section:
UIAtlas
ManagedStaticReference
Drilling down these items shows nothing.
I managed to clean these leaked instances crudely by doing this after scene switch:
- foreach(var atlas in Resources.FindObjectsOfTypeAll<UIAtlas>())
- {
- Texture tex = atlas.texture;
- GameObject.Destroy(atlas.spriteMaterial);
- GameObject.Destroy(atlas);
- GameObject.Destroy(tex);
- }
Any idea what could be causing this?
Thanks!
