Addressables OnSceneUnload Memory Leak

Hello,

we are currently trying to lower our memory consumption of our game. Therefore we are using Addressables in our projects and we are loading our scenes with it. After looking into the log i saw the following line

To Debug, run app with -diag-job-temp-memory-leak-validation cmd line argument. This will output the callstacks of the leaked allocations.

After starting our application with the flag we get a lot of similiar callstacks from where the allocations come from. The snapshot in the memory profiler tells me, that there is a leaked shell object which is still referenced from the SceneOperation. But i though that when loading a new scene (SceneLoadMode.Single) that all active (we are loading multiple scenes additive) scene handles get automatically released.

Any help with this issue would be great. :slight_smile:

We are using Addressables: 1.21.21
Unity: 2022.3.25f1

Allocation of 400 bytes at 7244c7f0 in block 1 (frameIndex=4, lifetime=15, age=10, state=OK)
0x00007ffdb805e342 (UnityPlayer) UnityMain
0x00007ffdb6ecfe7b (UnityPlayer) 
0x00007ffdb4c52bf8 (GameAssembly) AssetBundleProvider_Release_m95F1EE9F98EB926F4A535EA03F3DAFD7F1B86884 (at C:/Users/Maico/Documents/drovagame/Library/Bee/artifacts/WinPlayerBuildProgram/il2cppOutput/cpp/Unity.ResourceManager.cpp:25258)
0x00007ffdb28d2323 (GameAssembly) ProviderOperation_1_Destroy_mFFE84F1E3773422B8A4B9D8975EB73E72401CCA8_gshared (at C:/Users/Maico/Documents/drovagame/Library/Bee/artifacts/WinPlayerBuildProgram/il2cppOutput/cpp/Generics__185.cpp:16912)
0x00007ffdb2e7aae5 (GameAssembly) AsyncOperationBase_1_DecrementReferenceCount_m2134F44155382EA2F7CA0CA77A2F3E0E83BA7AD1_gshared (at C:/Users/Maico/Documents/drovagame/Library/Bee/artifacts/WinPlayerBuildProgram/il2cppOutput/cpp/Generics__24.cpp:26988)
0x00007ffdb4c6e6a7 (GameAssembly) GroupOperation_ReleaseDependencies_mC61C8336FBDB7D9D6CBFF04E772DDEE94E1650B2 (at C:/Users/Maico/Documents/drovagame/Library/Bee/artifacts/WinPlayerBuildProgram/il2cppOutput/cpp/Unity.ResourceManager__1.cpp:9074)
0x00007ffdb2e7aae5 (GameAssembly) AsyncOperationBase_1_DecrementReferenceCount_m2134F44155382EA2F7CA0CA77A2F3E0E83BA7AD1_gshared (at C:/Users/Maico/Documents/drovagame/Library/Bee/artifacts/WinPlayerBuildProgram/il2cppOutput/cpp/Generics__24.cpp:26988)
0x00007ffdb30704a0 (GameAssembly) AsyncOperationHandle_1_Release_m525B557AF9B665D33B03BB88680B2AEECB00C260_gshared (at C:/Users/Maico/Documents/drovagame/Library/Bee/artifacts/WinPlayerBuildProgram/il2cppOutput/cpp/Generics__25.cpp:10893)
0x00007ffdb28d234d (GameAssembly) ProviderOperation_1_Destroy_mFFE84F1E3773422B8A4B9D8975EB73E72401CCA8_gshared (at C:/Users/Maico/Documents/drovagame/Library/Bee/artifacts/WinPlayerBuildProgram/il2cppOutput/cpp/Generics__185.cpp:16932)
0x00007ffdb2e7aae5 (GameAssembly) AsyncOperationBase_1_DecrementReferenceCount_m2134F44155382EA2F7CA0CA77A2F3E0E83BA7AD1_gshared (at C:/Users/Maico/Documents/drovagame/Library/Bee/artifacts/WinPlayerBuildProgram/il2cppOutput/cpp/Generics__24.cpp:26988)
0x00007ffdb4c6b738 (GameAssembly) AsyncOperationHandle_Release_mD4ADD2AA46F56753B12E0916FA2A739A3EBB5762 (at C:/Users/Maico/Documents/drovagame/Library/Bee/artifacts/WinPlayerBuildProgram/il2cppOutput/cpp/Unity.ResourceManager__1.cpp:8247)
0x00007ffdb4c5a022 (GameAssembly) InstanceProvider_ReleaseInstance_m52D21820C36D02F3E2C0C7C89C0511648FF66A59 (at C:/Users/Maico/Documents/drovagame/Library/Bee/artifacts/WinPlayerBuildProgram/il2cppOutput/cpp/Unity.ResourceManager.cpp:28316)
0x00007ffdb2e7aae5 (GameAssembly) AsyncOperationBase_1_DecrementReferenceCount_m2134F44155382EA2F7CA0CA77A2F3E0E83BA7AD1_gshared (at C:/Users/Maico/Documents/drovagame/Library/Bee/artifacts/WinPlayerBuildProgram/il2cppOutput/cpp/Generics__24.cpp:26988)
0x00007ffdb4c61c1a (GameAssembly) ResourceManager_CleanupSceneInstances_m462175052395535F374CA0A1E1DE52E922504DF4 (at C:/Users/Maico/Documents/drovagame/Library/Bee/artifacts/WinPlayerBuildProgram/il2cppOutput/cpp/Unity.ResourceManager.cpp:8891)
0x00007ffdb47b8c2f (GameAssembly) AddressablesImpl_OnSceneUnloaded_m3BE985BC72C4FC0E4046123CB977B7E6AACCF4C8 (at C:/Users/Maico/Documents/drovagame/Library/Bee/artifacts/WinPlayerBuildProgram/il2cppOutput/cpp/Unity.Addressables.cpp:13207)
0x00007ffdb17a8176 (GameAssembly) il2cpp::vm::Runtime::InvokeWithThrow (at C:/Program Files/Unity/Hub/Editor/2022.3.38f1/Editor/Data/il2cpp/libil2cpp/vm/Runtime.cpp:609)
0x00007ffdb17a7c19 (GameAssembly) il2cpp::vm::Runtime::Invoke (at C:/Program Files/Unity/Hub/Editor/2022.3.38f1/Editor/Data/il2cpp/libil2cpp/vm/Runtime.cpp:594)
0x00007ffdb7bef898 (UnityPlayer) 
0x00007ffdb7bf73ac (UnityPlayer) 
f8 62 37 b9 fd 7f 00 00 06 00 00 00 00 00 00 00  .b7.............
ff ff ff ff 01 00 00 00 00 00 00 00 00 00 00 00  ................
53 00 00 00 01 00 00 00 5d 04 00 00 00 00 00 00  S.......].......
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00 00 00 00 00 00 00 00 10 2b 21 cf ae 02 00 00  .........+!.....
02 00 00 00 01 00 00 00 86 ba 0d 50 20 00 00 00  ...........P ...
00 00 00 00 00 00 00 00 f0 00 00 00 00 00 00 00  ................
00 00 00 00 00 00 80 3f b0 30 4a 72 ad 02 00 00  .......?.0Jr....

That line is related to UnsafeUtility allocations, such as those used for NativeCollections.

The leaked Shells are unrelated. Though you might still want to look at what’s holding the Scene Operation and by extension anything that it is holding on to.

How can i solve this native memory leak, because last line is the call “AssetBundleProvider_Release” and i though that all assets will be released with it. Is it because an asset/script inside an asset bundle is doing something with the UnsafeUtility and not disposing it?

This could be a bug with Addressables? It might be worth to file a bug report for this.

Thank you. I did a bug report as you asked. :slight_smile:

Did anything ever come of this? We are seeing the same problem related to async scene unloading.

Hello,

the bug is still under “Review”. Just got an update on it today. Our project is quite big (Build-Time 3-4h) so they asked me today if i could make the project smaller. But no further details if it’s a bug or if something is wrong with the addressables.

We also have a major issue with unloading scenes, we aren’t using addressables though. We get soft locked in build only, with complex scenes with over 15k GameObjects. Our bug report + repro project is currently being reviewed.

Hi

The issue is still under review. Johanhan’s project size is being assessed, but there’s no update yet on whether it’s a bug with Addressables. For your problem with complex scenes, it could be related to scene complexity. Watch the bug report for updates.