lightstone
lightstone copied to clipboard
Unused chunks should be unloaded to prevent excessive memory consumption
Right now the server will continually add chunks to its cache and won't remove them. Eventually this will lead to an OutOfMemoryError so we need some way of deciding when to unload chunks.
One option would be to use a LinkedHashMap in the chunk cache which allows iteration in the last access order. We'd also need to do a few checks to see if any players are near the chunk or if it was used recently (we need to be able to process physics/entities/etc on chunks near players).
I don't see why you need to add those checks. A LRU map should work fine. If there are players near by and they're active, it would be using the chunk, so it will naturally filter itself.
Also, it's just a cache, don't forget that.
Yeah that's actually a good point. Would just have to be a bit careful about keeping references to objects within chunks though, otherwise you could end up with two loaded into memory at once.