lightstone icon indicating copy to clipboard operation
lightstone copied to clipboard

Unused chunks should be unloaded to prevent excessive memory consumption

Open grahamedgecombe opened this issue 13 years ago • 2 comments

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).

grahamedgecombe avatar Apr 11 '11 08:04 grahamedgecombe

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.

Joe0 avatar May 12 '11 06:05 Joe0

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.

grahamedgecombe avatar Jun 01 '11 12:06 grahamedgecombe