This will definitely leak

I’ve made a procedural generation chunk thingy but I had to remove the chunks far away from players to save my PC from exploding

yay it worked but I saved the chunks to a table, and I don’t know where else to put the chunks

what do I do to make it optimized?

script: ( very shortened )

local ChunkController = require(script.ChunkController)
local Chunks = {}

while task.wait(5) do
	ChunkController.RemoveOutOfRange()
	local NewChunks = ChunkController.Generate(Chunks)

	for i, Chunk in pairs(NewChunks) do
		table.insert(Chunks, {
			["Name"] = Chunk.Name,
			["Pivot"] = Chunk:GetPivot()
		})	
	end
end

…what’s the ChunkController code??

the code doesn’t exist, I just shortened the code to make it easier to read

guys i need help

How do you expect us to help with that minimal amount of code? You gotta provide more with like how do you serialize a chunk at the moment for example

There is barely any code to look at to help you.

1 Like

Make sure you remove chunks from the table that aren’t needed anymore.

Without more code, there is little we can recommend you do.

Instead you should reuse the unused chunk.

1 Like

Instead of outright removing out-of-range chunks from the table, you could serialize and compress the chunk for caching purposes.

2 Likes

What I meant was to remove the chunks from the table of currently active chunks. Not actually delete the instances they are referencing.

Though depending on your usecase (procedural or not) you might want to actually delete generated instances.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.