PhysicsParts & PhysicsCollision memory usage gradually increasing

Hi, I’ve recently made a Tycoon game and I’ve been having problems combating the memory usage. My PhysicsCollision & PhysicsParts memory usage is slowly going up. My dropper script assigns a PhysicsCollision group to every dropper part it makes, so the dropped parts can’t collide with eachother. Is destroying the dropper part not enough?

I have a part that the dropper parts will eventually touch & get destroyed, which looks like this

local values = script.Parent.Parent.Parent.Parent:WaitForChild("values")
local moneyValue = values:WaitForChild("moneyValue")

local processed = setmetatable({}, { __mode = "k" })

local function onTouched(hit)
	-- dropperpart check
	if not hit or not hit:IsA("BasePart") or hit.Name ~= "DropperPart" then
		return
	end

	-- debounce per-instance
	if processed[hit] then
		return
	end
	processed[hit] = true

	-- clean up when part is destroyed
	local destroyingConn
	destroyingConn = hit.Destroying:Connect(function()
		processed[hit] = nil
		if destroyingConn then
			destroyingConn:Disconnect()
			destroyingConn = nil
		end
	end)

	-- increase moneyValue
	local dropValue = hit:FindFirstChild("MoneyValue")
	if dropValue and dropValue:IsA("IntValue") and hit.Parent then -- verify
		moneyValue.Value += dropValue.Value
		hit:Destroy()
	end
end

script.Parent.Touched:Connect(onTouched)

I’ve tried removing the assigned physicscollision group, but that somehow made the memory leak greater before destroying the dropper part.

I believe the PhysicsParts memory usage is a Roblox engine issue (as far as I’ve seen), and nothing much I can do about that. Am I doing something very wrong with my code?

Thanks for any possible suggestions!

2 Likes

One method i’ve heard of to help with performance, is if you need something later, don’t delete it, but reuse it.
Try just teleporting the parts that would be deleted, back to the positions where they would come out of the dropper. You save alot more memory by just positioning a part instead of having to do expensive creating, deleting and cleaning up.

2 Likes

Interesting, I could try to do something rather silly, instead of the ore getting destroyed, I’ll save it somewhere, if the dropper tries to spawn a new part, make it check if there is a saved version of itself, if there isn’t only then make a new dropper part.

I’ll try your suggestion & see if anything changes, Thanks!

Your suggestion worked flawlessly!

Doing it this way DID stop the memory increasing to insane values.
Thanks!

1 Like

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