Posted May 27, 201510 yr I have a (server-side) mod which is accessing a large number of chunks when it activates. Once accessed, these chunks do not need to remain in the cache as they are not likely to be accessed again for a long time. The problem is that the Java heap memory runs out. This is because the IChunkProvider.getLoadedChunkCount() shows me that I have many thousands of chunks still in the cache, exhausting the available memory. My question is, how can I kick these out of the cache? I've tried all of these: world.getChunkProvider().saveChunks(true,null); world.getSaveHandler().flush(); world.getChunkProvider().unloadQueuedChunks(); world.getWorldChunkManager().cleanupCache(); (new Chunk(world, x, y)).setChunkLoaded(false); However none of them seem to affect the cache size, which goes relentlessly upwards until a malloc error ends its life. What is the correct way to flag these cached chunks for unloading? TIA
May 27, 201510 yr ChunkProviderServer.unloadAllChunks.. This appears to unload all the chunks... I wonder how it does that.. public void unloadAllChunks() { Iterator iterator = this.loadedChunks.iterator(); while (iterator.hasNext()) { Chunk chunk = (Chunk)iterator.next(); this.dropChunk(chunk.xPosition, chunk.zPosition); } } It loops through all loaded chunks.. can calls dropChunk.... But I only want to unload one chunk... I wonder what should I do? I do Forge for free, however the servers to run it arn't free, so anything is appreciated. Consider supporting the team on Patreon
May 29, 201510 yr Author Thanks for this; I'd found IChunkProvider but not ChunkProvderServer. Obviously now I can call dropChunk() to get rid on the individual chunks (for some reason, dropChunk does not appear to exist in IChunkProvider). I assume that the instance of ChunkProviderServer to use this one -- ChunkProviderServer cps; cps = MinecraftServer.getServer().worldServers[0].theChunkProviderServer; cps.saveChunks(true,null); // make sure we have no pending updates cps.dropChunk(x,z); ... and indeed, the getLoadedChunkCount() from both the IChunkProvider and the ChunkProviderServer now never goes above approx 700, and the memory death is averted. Thanks for the help
May 29, 201510 yr ChunkProviderServer cps; cps = MinecraftServer.getServer().worldServers[0].theChunkProviderServer; So, you only need that for the overworld then? Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! | mah twitter This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.