Projects that use Janitor
If your project uses Janitor, leave a PR on the readme!
- Be an Alien: Renewal by PeZsmistic
- Benchmarker by boatbomber
- RBLX04 by movsb
- RepoToRoblox by a great friend (boatbomber lol)
- Science Simulator by Interbyte Studio
- Studio Tweaks by PeZsmistic
Why use Janitor?
- Janitor makes dealing with garbage collection much less annoying and stressful because it manages them all in a nice interface.
Janitor:Addreturns whatever was added, which Maid doesn’t.
Janitor:Addalso accepts a custom method, if you want to call
Tween. You can see this being used in the JanitorPromise library.
Janitor:Addalso accepts a custom reference to store under, which keeps the api more consistent. (
Maid.A = Xand
Janitor:Add(X, nil, "A")and
- Janitor also allows linking to an Instance, so when the Instance is destroyed, the Janitor cleans up everything along with it.
Some less important benefits:
- Runs a little better than Maid does.
Which version should you use?
- If you use Promise, you should take a look at either JanitorPromise or JanitorPromiseLight.
- If you don’t use Promise, you should look at either Janitor or JanitorLight.
- If you don’t want extra dependencies, use one of the Light libraries.
Benchmarks ran on an R9 3900X with 32GB of DDR4-3600 RAM.
Instantiates a new Janitor object.
Determines if the passed object is a Janitor.
The object you are checking.
[boolean] Whether or not the object is a Janitor.
function Janitor:Add(Object, MethodName, Index)
Object to Janitor for later cleanup, where
MethodName is the key of the method within
Object which should be called at cleanup time. If the
Object itself will be called instead. If passed an index it will occupy a namespace which can be
Remove()d or overwritten. Returns the
The object you want to clean up.
[string | true?] MethodName
The name of the method that will be used to clean up. If not passed, it will first check if the object’s type exists in TypeDefaults, and if that doesn’t exist, it assumes
The index that can be used to clean up the object manually.
[any] The object that was passed.
Adds a promise to the janitor. If the janitor is cleaned up and the promise is not completed, the promise will be cancelled.
The promise you want to add to the janitor.
Cleans up whatever
Object was set to this namespace by the 3rd parameter of
The index you want to remove.
[Janitor] The same janitor, for chaining reasons.
Gets whatever object is stored with the given index, if it exists. This was added since Maid allows getting the task using
The index that the object is stored under.
[any?] This will return the object if it is found, but it won’t return anything if it doesn’t exist.
Calls each Object’s
MethodName (or calls the Object if
MethodName == true) and removes them from the Janitor. Also clears the namespace. This function is also called when you call a Janitor Object (so it can be used as a destructor callback).
:Cleanup() and renders the Janitor unusable.
function Janitor:LinkToInstance(Object, AllowMultiple)
“Links” this Janitor to an Instance, such that the Janitor will
Cleanup when the Instance is
Destroyed() and garbage collected. A Janitor may only be linked to one instance at a time, unless
AllowMultiple is true. When called with a truthy
AllowMultiple parameter, the Janitor will “link” the Instance without overwriting any previous links, and will also not be overwritable. When called with a falsy
AllowMultiple parameter, the Janitor will overwrite the previous link which was also called with a falsy
AllowMultiple parameter, if applicable.
The instance you want to link the Janitor to.
Whether or not to allow multiple links on the same Janitor.
[RbxScriptConnection] A pseudo RBXScriptConnection that can be disconnected.
Links several instances to a janitor, which is then returned.
All the instances you want linked.
[Janitor] A janitor that can be used to manually disconnect all LinkToInstances.