function Maid.doCleaning(J)local s=J._tasks for J,q in pairs(s)do if typeof(q)=="\082\066\088\083\099\114\105\112\116\067\111\110\110\101\099\116\105\111\110"then s[J]=nil q:Disconnect()end end local q,d=next(s)while d~=nil do s[q]=nil if type(d)=="\102\117\110\099\116\105\111\110"then d()elseif typeof(d)=="\082\066\088\083\099\114\105\112\116\067\111\110\110\101\099\116\105\111\110"then d:Disconnect()elseif d.Destroy then d:Destroy()elseif d.destroy then d:destroy()end q,d=next(s)end end
--- Cleans up all tasks.
-- @alias Destroy
function Maid:doCleaning()
	local tasks = self._tasks

	-- Disconnect all events first as we know this is safe
	for index, task in pairs(tasks) do
		if typeof(task) == "RBXScriptConnection" then
			tasks[index] = nil
			task:Disconnect()
		end
	end

	-- Clear out tasks table completely, even if clean up tasks add more tasks to the maid
	local index, task = next(tasks)
	while task ~= nil do
		tasks[index] = nil
		if type(task) == "function" then
			task()
		elseif typeof(task) == "RBXScriptConnection" then
			task:Disconnect()
		elseif task.Destroy then
			task:Destroy()
		elseif task.destroy then
			task:destroy()
		end
		index, task = next(tasks)
	end
end
