Open Meldexun opened 2 years ago
Finally got around to this issue, thanks for the report. Learned about weak references recently, and about WeakHashMap. I think this should eliminate the issue entirely. What do you think?
WeakHashMap: "Hash table based implementation of the Map interface, with weak keys." (https://docs.oracle.com/javase/8/docs/api/java/util/WeakHashMap.html)
So you would need to change it to use the entity as the key. Then this should work fine.
Edit: Keep in mind that the values of a WeakHashMap are held by strong references. This means the entries of the map won't be cleared if the value prevent the keys from being garbage collected. This is the case here since LivingEntityData holds a reference to the Entity object.
Fixed in my fork if this was not fixed already, alongside with another huge one (i talk about 12gb in a few minutes)
Describe the bug The
EntityDatabase#entryMap
map storesLivingEntityData
as values which have a reference to their entity instance. This map should be cleared inEntityDatabase#updateClient()
but I think it would be better to clear the map with anIWorldEventListener#onEntityRemoved(Entity)
and thePlayerLoggedOutEvent
. Otherwise while in the main menu aWorldClient
will still be loaded in memory.https://github.com/mobends/MoBends/blob/3b56b02e59fcf2d8571d3fedb6ceee8f8824ba05/src/main/java/goblinbob/mobends/core/data/EntityDatabase.java#L22
To Reproduce Steps to reproduce the behavior:
WorldClient
instance not being garbage collectedContext (please complete the following information):