Memory usage over 1GB

Hello, as I was testing my game and modifying my main script, in several of my tests I had observed that the memory usage was over 1GB, around 1.3K MB above the target limit imposed. After disabling certain scripts/objects that consumed an excess of memory, around 700 MB was deducted from the over-all memory consumption. As far as I know, my game only runs on one script with 73 lines of code (including comments), and only four loops, yet both LuaHeap and Script seem to be contributing to the mass of consumption of PlaceMemory. Is there any way why the client is receivng this much memory from just one script?

P.S. There are tools with sounds and animations, however the scripts that run them have been disabled, and Animation’s MB consumption amounts to around 280 MB.

The client’s performance stats for reference:

PlaceMemory under client:

The script:

local Colors = {
	"Bright red",
	"New Yeller",
	"Pine Cone",
	"Gold",
	"Institutional White"
}


local shelves = game:GetService("Workspace").Shelves:GetChildren()

for _, shelf in ipairs(shelves) do
	
	---
	
	local ItemDisplay = shelf:FindFirstChild("ItemsDisplay").BillboardGui.Frame.TextLabel --Item Display UI
	local itemCapacity = #shelf:FindFirstChild("Items"):GetChildren()
	local itemsLeft = shelf:FindFirstChild("ItemsLeft")
	itemsLeft.Value = itemCapacity
	ItemDisplay.Text = itemsLeft.Value.."/"..itemCapacity
	print(itemCapacity)
	
	itemsLeft:GetPropertyChangedSignal("Value"):Connect(function()
		ItemDisplay.Text = itemsLeft.Value.."/"..itemCapacity
	end)

	---

	local clickParts = shelf.Click:GetDescendants() 
	
	-- Shelf deletion by player

	for i,v in ipairs(clickParts) do
		if v:IsA("ClickDetector") then
			v.MouseClick:connect(function(playerWhoClicked)
				local itemsTable = v.Parent.Parent.Parent:FindFirstChild("Items"):GetChildren()
				if #itemsTable == 0 then
					return
				end
				local itemToBeDestroyed = itemsTable[math.random(1, #itemsTable)] 
				table.remove(itemsTable, i)
				itemToBeDestroyed:Destroy()
				itemsLeft.Value -=1   
				print(#itemsTable)
				
				--Cloning to player's backpack
				
				local itemCloneTable = game:GetService("ServerStorage"):FindFirstChild("StoreProducts"):GetChildren()
				for i,v in ipairs(itemCloneTable) do
					if v.Part.BrickColor == itemToBeDestroyed.BrickColor then
						local itemCloned = v:Clone()
						itemCloned.Parent = playerWhoClicked.Backpack
					end
				end
			end)
		end
	end

	---

	local itemsTable = shelf:FindFirstChild("Items"):GetChildren()
	
	-- Change colors
	
	for i,v in ipairs(itemsTable) do
		v.BrickColor = BrickColor.new(Colors[math.random(1, #Colors)])
	end
end

How many objects are in shelves?

There are two objects in shelves, with their own children

image
image

The ‘items’ folder under ‘Shelf’ contains around 119 children.

Maybe try to connect some part and remove not visible parts? No idea how that would effect anything but as you said here

It seems to do something.

1 Like

Whoops, sorry, I misplaced the 1.2K with 700, will consider your suggestion since a 700 MB reduction for me is still significant nonetheless.

For my level of familiarity with Luau, I’m not quite sure what to make of this. Whilst having browsed dozens of resources including memory and task scheduling and having experimented with the loop iterating over a lesser number of objects and still returning a high memory consumption rate, I’ve come to draw a SURE hypotheses that:

My game only runs on one script, and based on its contents and what other people have described as bad practices, it is horribly optimized and in line with said practices.

Further feedback on what the issue may be with the memory is much appreciated! I am aware that Roblox allocates RAM depending on your device, so my memory consumption could be linear with that.