pgimeno wrote: ↑Mon Oct 25, 2021 6:24 pm
Yeah, thanks milon.
Because the object is no longer usable, and trying to use it may crash your program; it also prevents the Lua-side object from being released.
pgimeno wrote: ↑Mon Oct 25, 2021 6:24 pm
Because the object is no longer usable, and trying to use it may crash your program; it also prevents the Lua-side object from being released.
But trying to use nil instead of a released object may also cause you to crash, so in that sense it makes no difference. The Lua-side object not getting garbage collected is true unless the variable is local.
ReFreezed wrote: ↑Mon Oct 25, 2021 9:04 pm
But trying to use nil instead of a released object may also cause you to crash, so in that sense it makes no difference. The Lua-side object not getting garbage collected is true unless the variable is local.
Yes, but a released object evaluates to true, while nil evaluates to false, so if you're checking using if myobject then... it will crash if you don't set it to nil (or false, which may be preferable in some cases, especially in arrays, to avoid creating a hole).
pgimeno wrote: ↑Tue Oct 26, 2021 10:23 am
Yes, but a released object evaluates to true, while nil evaluates to false, so if you're checking using if myobject then... it will crash if you don't set it to nil
Sure, but then I'd say the variable should be set to nil not because "it's best to do so", but rather "because the other piece of code expects the variable to be an object or nil". If a variable is set to nil for no concrete reason then I would raise an eyebrow when looking at the code. Also, if an object is released and then used then the program is simply broken and should be fixed (e.g. by setting myobject to nil and adding 'if myobject then' where it matters).