-
Notifications
You must be signed in to change notification settings - Fork 84
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
Fix minor memory leaks #258
Conversation
ad67d63
to
09432dd
Compare
Can you use a WeakHashMap instead and lazily initialize the entities when they go missing? That way you won't have to rely on calling the cleanup function at the right time |
Good idea. Thanks for that suggestion, in the process of verifying it worked I actually managed to find two more leaks: one in vanilla and another in NEI (fix included here). |
Ah sorry, now looking through it I'm not sure a weak map is the best solution. The weak map is the only thing that ever holds references to these entities, as spawnEntityInWorld is never called, so they will be collected on every gc cycle, causing wasteful entity re-creating. The world object on these entities seems to be reset in the renderer class, maybe just set the world object to null after the constructors are run, and add setting it to null to |
I believe the entities are referenced by the world that contains them (the |
The problem is that they're not added to that list - the Entity constructor does not put the entity in the loaded list. Only when the |
Interesting, I am pretty sure I saw them in Should I just revert to my original solution then? I'm not sure how mods will react to the world object on the entity being null. |
Yeah, the original should be ok |
This reverts commit 91bb997.
Updated. |
#258 addresses the memory leak in ItemMobSpawner. Unfortunately the clean up handler is not consistently called on every world unloaded. This PR fixes this issue by moving the call out of that if block
GTNewHorizons#258 addresses the memory leak in ItemMobSpawner. Unfortunately the clean up handler is not consistently called on every world unloaded. This PR fixes this issue by moving the call out of that if block (cherry picked from commit 31173a1)
#258 addresses the memory leak in ItemMobSpawner. Unfortunately the clean up handler is not consistently called on every world unloaded. This PR fixes this issue by moving the call out of that if block
ItemMobSpawner
uses a hash map to cache entity instances for rendering them inside spawners. These entities hold a reference to a client world in order to render correctly. However, based on reading that code, that reference only appears to be updated when the spawners are visible in NEI. This leads to the spawners retaining an extra, unnecessaryWorldClient
instance when the player changes dimensions.I've fixed this problem by simply removing and recreating the entities if the client world changes.
NEIController
keeps a manager instance for a GUI even after it's closed. If the player then switches dimensions, the previous world is not able to be garbage collected till the GUI is reopened. This is fixed by settingmanager
back tonull
once the GUI is closed.