--[[
	
	Alternative to game.Debris:AddItem() which runs on heartbeat (and runs better, for that matter)
	
	60hz accurate
	
	also supports array of objects in 1st arg
		
--]]



function Step()
	--- scan garbage for items that are expired and clean them up
	for i = #garbage, 1, -1 do
		local v = garbage[i]
		local obj = v[1]
		local t = v[2]
		local removetime = v[3]
		local tp = (tick() - t)
		if tp >= removetime then
			if type(obj) == "table" then
				for _, objchild in ipairs(obj) do
					objchild:Destroy()
				end
			else
				obj:Destroy()
			end
			table.remove(garbage, i)
		end
	end
end


coroutine.wrap(function() --- main loop
	while _L.Services.RunService.Heartbeat:Wait() do
		Step()
	end
end)()


return function(obj, t)
	if not t then
		t = 10
	end
	--- add to garbage
	table.insert(garbage, {obj, tick(), t})
end
