Forest Logo
search
package_2

janitor

By @nazumah

Roblox

Mirrored

Janitor

Wally License Luau

Janitor is a powerful resource management and cleanup utility for Luau on Roblox. It helps developers track and dispose of objects, connections, and tasks, ensuring that memory leaks and dangling listeners don't accumulate in complex systems.


Technical Advantages

  • Method Agnostic Disposal: Supports any object with standard disposal methods like .Destroy(), .Disconnect(), or .cancel().
  • Indexed Cleanup: Assign unique keys to objects. Adding a new object to an existing index automatically cleans up the previous occupant.
  • Async Interoperability: First-class support for the Async library. Adding an Async object to a Janitor ensures it is cancelled if the Janitor is destroyed.
  • Instance-Linked Lifecycle: Automatically trigger cleanup when a specific Roblox Instance is destroyed using LinkToInstance.
  • First-Class IntelliSense: Uses explicit Static and Janitor types to ensure that require returns a fully-typed interface.

Installation

Wally

Update your wally.toml:

[dependencies]
Janitor = "nazumah/janitor@1.1.4"
Async = "nazumah/async@1.0.4"

Quick Start

1. Tracking Multiple Objects

local Janitor = require(path.to.Janitor)
local myJanitor = Janitor.new()

-- Add a Roblox instance
local part = myJanitor:Add(Instance.new("Part"), "Destroy")

-- Add an event connection
myJanitor:Add(part.Touched:Connect(print), "Disconnect")

-- Add a custom function
myJanitor:Add(function()
    print("Custom cleanup logic!")
end, true)

-- Cleanup everything
myJanitor:Cleanup()

2. Indexed Retrieval

myJanitor:Add(Instance.new("Part"), "Destroy", "MainPart")

-- Later...
local part = myJanitor:Get("MainPart")

3. Destruction Linking

local npc = workspace.NPC
myJanitor:LinkToInstance(npc)

-- When npc is destroyed, myJanitor:Cleanup() is called automatically.

Documentation

  • Why Use Janitor?
  • API Reference

License

Licensed under the MIT License.

Package Details

Install command (Click to copy)


Version

1.1.4

License

MIT

check_circle

Safe for commercial use

infoLicense identified from the packaged LICENSE file; the manifest declared none.

Automated license review — not legal advice.