Forest Logo
search
Cleaner

Cleaner

By @stratizverified

Roblox

Cleaner

A small Maid style helper for tracking objects and tearing them down together.

Usage

local Cleaner = require(path.to.Cleaner)

local cleaner = Cleaner.new()

cleaner:Add(workspace.Part)
cleaner:Add(part.Touched:Connect(onTouch), task.spawn(runLoop))
cleaner:Add(function()
    print("cleaned up")
end)

cleaner:Destroy()

API

Cleaner.new()

Returns a new cleaner.

Cleaner:Add(...)

Tracks one or more objects. Accepts an Instance, an RBXScriptConnection, a thread, a function, or any table with a Destroy method. Adding the same object twice is ignored. Returns the object when given one, or a table of the objects when given several.

Cleaner:Remove(...)

Stops tracking one or more objects. They are not cleaned.

Cleaner:Digest(object, includeFunctions)

Scans a table, such as an OOP object, and tracks every cleanable value inside it. Functions are skipped unless includeFunctions is true, so methods on plain table objects are not called during cleanup. Returns a table of the values that could not be tracked.

Cleaner:Destroy()

Cleans every tracked object, then clears the list. Instances and tables are destroyed, connections are disconnected, threads are cancelled, and functions are called. Also available as Cleaner:Clean().

Package Details

Install command (Click to copy)


Version

1.1.0

License

MIT

check_circle

Safe for commercial use

Automated license review — not legal advice.