-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
References bound to a Scene Context stay in memory after scene change #654
Comments
Did you find any solution/workaround for this? I also have leaks in my project which I believe could be related to this behavior. |
I find ZEN_INTERNAL_NO_POOLS define word can fix the issue in the sample project. |
Here is the fix: |
Hello, i've found the same issue as here, have anyone find the solution? |
@sapiscow Have you tried using Zenject's current project? This version is obsolete and hasn't been updated in quite a bit. Check https://github.com/modesttree/Zenject for the current version. |
Yes, i've tried the latest version (Extenject 9.2.0) in Unity 2020 LTS, did you solve your problem with only update the Zenject? or |
@sapiscow Not really. We made a workaround ourselves as Zenject wasn't being updated at that time (and we didn't know about Extenject). It's been a while, and I no longer have easy access to that git history to verify for sure what we did (we tried a lot of stuff). However, I suspect that the key of the fix was adding this in
Give it a try. |
@Racso After i add that code in SceneContext.cs, the GameInstaller (an installer script that also in the same gameobject as SceneContext) is cleared from memory after the scene unloaded, but the others is still have issue |
@sapiscow OK, last shot I can give you: In your installers (e.g. your GameInstaller), add code in
Where For example: if you had this in the installer:
You would add this in
|
That being said, I suspect you have other kind of issue. My last suggestion probably won't make a difference because if your GameInstaller is being unloaded correctly (as you mentioned), it won't keep references alive in memory (therefore, nullifying the pointers is useless). Maybe you have statics in your code, or something similar? |
@Racso the GameInstaller doesn't have any reference to another, it just contains Bind functions for any interface that used in the scene. And now, i've tried the sample project from Zenject, there are two sample projects, one that simple and one advance. Thank you btw @Racso for your help |
Hello!
I've found that Zenject somehow is "leaking" assets in memory. What I mean by this is that assets that are bound to a Scene Context are kept in memory even when the Scene has been changed. I have the theory that some static reference is keeping those assets from being collected by the GC, but that's all I got; I couldn't pinpoint the exact cause of the problem.
Any help to solve this issue (or find a workaround for it) would be appreciated!
Setup to reproduce:
TestInjectableComponent
. TheTestInjectableComponent
should have some references to some assets, such asSprites
(e.g. aList<Sprite>
). The MonoInstaller binds classTestInjectableComponent
to that instance.TestInjectableComponent
(with the references to the assets). No Zenject-related components should exist here.Steps to reproduce:
Note: to verify Assets in memory, use Unity's profiler to take a Memory Snapshot.
Sample Project
I've attached a test project where you can verify this behavior. Use the keyboard to change to the desired scene: S for the "Starting Scene", N for the "No-Zenject Scene" and Z for the "Zenject Scene".
Zenject Leak Test.zip
The text was updated successfully, but these errors were encountered: