Suppose I have a “while” loop that contains a “pcall”. Inside the pcall I create a new instance of a class. If an error occurs after creating this new instance, but the error is caught by the pcall (allowing the loop to continue), will the new instance of the class be garbage collected?
Here is an example of what I’m talking about:
local myClass = require(classReference)
while true do
success, err = pcall(function()
local newInstance = myClass.new()
task.wait(1)
--Lets say I error here before im able to erase my instance--
newInstance:CleanUp()
end)
if err then
warn(err)
continue
end
end
Fair but what would be the difference if I had just a regular variable be defined and the thread stopped versus an instance of a class. Because in theory aren’t they both only referenced inside of the enclosed loop?