Skip to main content

Sweeper

Garbage colection package, similar to Maid and Janitor.

Basic Usage:

local mySweeper = Sweeper.new()
local connection = RunService.Heartbeat:Connect(print) -- Print delta time
mySweeper:Add(connection)
task.wait(1)
mySweeper:Clean() -- Disconnects

Types

Sweepable

type Sweepable = Instance | () → () | {[string]() → ()}

Describes somethign a Sweeper can cleanup. This is currently any Instance, function or table with one of the following methods:

  • "Destroy"
  • "Disconnect"
  • "disconnect"
  • "destroy"

Functions

new

Sweeper.new() → ()

Create new sweeper

Is

Sweeper.Is(objSweeper?) → ()

Check if obj is a sweeper.

Add

Sweeper.Add(
selfSweeper,
taskSweepable
) → ()

Adds a task to the sweeper to be cleaned up.

Clean

Sweeper.Clean(selfSweeper) → ()

Clean up everything that has been added to the sweeper.

Destroy

Sweeper.Destroy(selfSweeper) → ()

Same as Sweeper.Clean

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Create new sweeper",
            "params": [],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 52,
                "path": "packages/sweeper/source/init.luau"
            }
        },
        {
            "name": "Is",
            "desc": "Check if `obj` is a sweeper.",
            "params": [
                {
                    "name": "obj",
                    "desc": "",
                    "lua_type": "Sweeper?"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 61,
                "path": "packages/sweeper/source/init.luau"
            }
        },
        {
            "name": "Add",
            "desc": "Adds a task to the sweeper to be cleaned up.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Sweeper"
                },
                {
                    "name": "task",
                    "desc": "",
                    "lua_type": "Sweepable"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 68,
                "path": "packages/sweeper/source/init.luau"
            }
        },
        {
            "name": "Clean",
            "desc": "Clean up everything that has been added to the sweeper.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Sweeper"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 98,
                "path": "packages/sweeper/source/init.luau"
            }
        },
        {
            "name": "Destroy",
            "desc": "Same as [Sweeper.Clean]",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Sweeper"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 125,
                "path": "packages/sweeper/source/init.luau"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "Sweepable",
            "desc": "Describes somethign a Sweeper can cleanup. This is currently any `Instance`, function or table with one of the following\nmethods:\n- \"Destroy\"\n- \"Disconnect\"\n- \"disconnect\"\n- \"destroy\"",
            "lua_type": "Instance | () -> () | { [string]: () -> () }",
            "source": {
                "line": 40,
                "path": "packages/sweeper/source/init.luau"
            }
        }
    ],
    "name": "Sweeper",
    "desc": "Garbage colection package, similar to `Maid` and `Janitor`.\n\nBasic Usage:\n```lua\nlocal mySweeper = Sweeper.new()\nlocal connection = RunService.Heartbeat:Connect(print) -- Print delta time\nmySweeper:Add(connection)\ntask.wait(1)\nmySweeper:Clean() -- Disconnects\n```",
    "source": {
        "line": 25,
        "path": "packages/sweeper/source/init.luau"
    }
}