Skip to main content

Why use Janitor?

Most of what I can say about why use something similar to Janitor has already been said by Quenty in his RDC 2020 talk, so this page will only cover the reasons to use Janitor itself.

Ease of use

Janitor makes dealing with garbage collection much less annoying and stressful because it manages them all in a nice interface.

High Performance

While I don't really recommend using Janitor if you're gonna be cleaning up every frame, it is significantly faster than any other library with a similar API design.

Returning

Janitor:Add() returns the first object passed, which Maid does not.

Custom Cleanup Methods

With Maid, you can't tell it to do anything other than :Destroy(), :Disconnect(), or call something. Janitor allows any method you choose to be called for cleanup. This includes Tween:Stop(), Humanoid:BreakJoints(), or Tool:Deactivate(). You can see this being used in the Janitor:AddPromise() method.

API Consistency

Janitor:Add() also accepts a custom reference to store under, which keeps the API more consistent.

JanitorMaidTrove
Adding an InstanceJanitor:Add(Instance)Maid:GiveTask(Instance)Trove:Add(Instance)
Adding an Instance with a given indexJanitor:Add(Instance, false, "Index")Maid.Index = InstanceCAN NOT DO THIS
Adding an Instance with a cleanup methodJanitor:Add(Tween, "Cancel")CAN NOT DO THISTrove:Add(Tween, "Cancel")
Removing an InstanceJanitor:Remove("Index")Maid.Index = nilCAN NOT DO THIS
Removing without cleanupJanitor:RemoveNoClean("Index")CAN NOT DO THISCAN NOT DO THIS

LinkToInstance

Janitor also allows linking to an Instance via the Janitor:LinkToInstance() method. This allows the Janitor to cleanup everything added to it when an Instance has its Instance:Destroy() method invoked.

Native support for Promises

Janitor is the only library of its kind that supports cancelling Promises.

TypeScript Support

Janitor has the best TypeScript support of any library like it. You have full intellisense with the objects stored in it, as well as the methods you can use to cleanup with.