Skip to content
This repository was archived by the owner on Jun 14, 2022. It is now read-only.
LucasMZ edited this page Aug 29, 2021 · 5 revisions

Recycler

.new()

Creates a recycler object!

:AddToGarbage(object)

Adds an object to weak garbage, it can still be garbage collected by Lua, however it will stay on a temporary storage until then.

:AddToStrongGarbage(object)

Adds an object to a strong garbage, the object passed will never be garbage collected, it can only be garbage collected if the recycler object gets collected, or if an object was re-used from it.

:GetObject()

Returns an object if there is one to reuse.

It can return an object if there if there's a :OnNewObject handler, which returns one.

:OnNewObject(function()

Sets a handler function to when there is no available object to re-use on :GetObject, whatever it returns will be returned on :GetObject when there is no object to re-use.

:OnDestroyed(function(object)

Sets a handler for when :GetObject is called, and there is an object to reuse, this should be used to prepare an object for when it needs to be reused.

Despite the name, :OnDestroyed like stayed above, doesn't fire when an object is added to garbage, instead it fires on :GetObject if there's an object to re-use. Therefore, if you need to change things when an object is destroyed, change it before sending it to the garbage. Most use-cases won't require this to be a thing, therefore this is an optimization.

Clone this wiki locally