Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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

  • 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.  ;D

 

Thanks for the help

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.