function recyclingBin.Allocate(J,K,L,M)local V={}local U=0 for M,c in pairs(M:GetChildren())do if c:IsA(K)then U=U+1 if U>L then J:Recycle(c)else V[U]=c end end end while U<L do U=U+1 V[U]=J:Pull(K,M)end return V end return recyclingBin
-- Allocate works similarly to Pull, except it tries to reuse objects that exist in the specified bin.
-- This removes the need to recycle every object during every frame.

function recyclingBin:Allocate(objectType, needed, bin)
	local allocation = {}
	local allocated = 0
	for _, v in pairs(bin:GetChildren()) do
		if v:IsA(objectType) then
			allocated = allocated + 1
			if allocated > needed then
				self:Recycle(v)
			else
				allocation[allocated] = v
			end
		end
	end
	while allocated < needed do
		allocated = allocated + 1
		allocation[allocated] = self:Pull(objectType, bin)
	end
	return allocation
end

return recyclingBin
