Fabric API

Fabric API

106M Downloads

Memory leak if other mods do their own chunk loading

warjort opened this issue ยท 1 comments

commented

From the discussion on the closed issue #1819

This has been an issue before when a mod decides it wants to modify(optimise) the chunk loading.
i.e. it ends up moving the chunk unload and hence setLoadedToWorld() calls to mod code.

Is there a reason why the above unload mixin doesn't run from inside WorldChunk.setLoadedToWorld()
when the loadedToWorld state changes from true -> false?

Basically if you have a mod that does its own chunk loading like:
https://github.com/gnembon/fabric-carpet/blob/b935fadadf11f685d85300d28da3de6ad8ce6113/src/main/java/carpet/mixins/ThreadedAnvilChunkStorage_scarpetChunkCreationMixin.java#L372

The ThreadedAnvilChunkStorageMixin won't know about it and this will lead to a memory leak here:

private final Set<WorldChunk> loadedChunks = new HashSet<>();

commented

Is there a reason why the above unload mixin doesn't run from inside WorldChunk.setLoadedToWorld()
when the loadedToWorld state changes from true -> false?

On the client, this method is never called, so we would need to hold the chunks on the client anyway. On the server, I think the event fires a bit after loadedToWorld is set to false to ensure the chunk is fully loaded. I'd say if other mods do their own chunk loading/unloading it's reasonable to expect them to fire the events correctly, otherwise mods keeping track of loaded chunks similarly to Fabric will also have problems.