if I create a BindableEvent and if this BindableEvent has no connections, no parent and no references will it be garbage collected?
Example
-- create a BindableEvent
local bindableEvent = Instance.new("BindableEvent")
-- connect a function to the event
local connection = bindableEvent.Event:Connect(function() end)
-- disconnect the function
connection:Disconnect()
-- remove reference
bindableEvent = nil
so after the code above has run will it produce a memory leak?
It will not produce a memory leak from testing using the debug library.
Using looping code it will peak then reset to a low value. It seems the instances in nil get cleaned up eventually as there is no reference to it within the code. This will change if you put them in a table and such.
Also I highly appreciate your work and tutorials @5uphi keep it up .
debug.setmemorycategory("BindableEvents Tests")
print("Running")
game:GetService("RunService").Heartbeat:Connect(function(deltaTime)
for i = 1, 100 do
-- create a BindableEvent
local bindableEvent = Instance.new("BindableEvent")
-- connect a function to the event
local connection = bindableEvent.Event:Connect(function() end)
-- disconnect the function
connection:Disconnect()
-- remove reference
--bindableEvent = nil
end
end)