Instance.old
is basically what it sounds like. It’s like Instance.new
, except instead of destroying instances, it recycles them.
It was designed to mimic Instance.new, except with a few more features, and potentially better performance for certain use cases. Here’s an example script:
Instance = require(script.Instance_custom)
Parts = {}
for i=1,5 do
Parts[i] = Instance.old("Part",workspace)
Parts[i].Color = Color3.new(1,0,0)
end
Parts[1]:Destroy()
Parts[2]:Destroy()
Parts[3]:Destroy()
local RecycledPart = Instance.old("Part")
RecycledPart.Color = Color3.new(0,1,0)
RecycledPart.Parent = workspace
local AnotherRecycledPart = Instance.old("Part",{
Parent = workspace,
Color = Color3.new(0,0,1)
})
As you can see, it also offers something similar to what LoadLibrary(“RbxUtility”).Create
used to do. This is also pretty optimized because it sets the Parent property last.
When you call “Destroy” on Instances created with Instance.old
, the module disconnects any event connections associated with the instance, then adds it to a recycling bin folder. When Instance.old
is called to get a new Instance, the module looks through the recycling bin to find the requested class type. If it can’t find that class type, it creates a new one. In theory, this should improve performance because Roblox won’t have to create entire new Instances all the time. It’ll be re-using old ones.
Things to keep in mind:
- Objects made with
Instance.old
have events disconnected when destroyed, but other properties are not guaranteed to be set to the default when first called upon! Make sure you are explicit with any properties you want. - Objects created with
Instance.old
are basically never deleted, so if they’re all being used at once it’ll keep making new ones and keep all of them, even after they’re potentially not being used. - This hasn’t actually been benchmarked yet.
Clickable Links/Buttons:
← this is particularly cool imo
I made this for fun. I have yet to do benchmarks because I’m lazy. I might post a benchmark later. If you want to do a benchmark yourself, I’d appreciate it if you’d post the results here!
Drop constructive criticisms below if you have any.