Does the garbage collector have (contain) nil values?

The title explains it all but someone told me it does. I don’t think it does but just asking to verify and in which cases would something nil be collected (if gc does have nil values).

1 Like

Title doesn’t explain it at all :sweat_smile: What do you mean “have” values?

2 Likes

Whether it contains nil values or not, sorry about that.

2 Likes

Yeah, that doesn’t mean anything to me, sorry :-/

The GC doesn’t “have values”, it collects (frees) them when they’re garbage (not used anywhere).

3 Likes

I’m not very educated on the subject so that’s why I’m asking - sorry for bad explanations. Is it possible for nil to exist within the gc?

2 Likes

As someone pointed out the gc doesn’t contain anything.

All it can do in roblox is tell you how much memory is being used.
It doesn’t store values, it doesn’t contain nil or anything like that.

Behind the scenes it works so that anything that cannot be used anymore will be removed from memory.

Say you call :Destroy() on a part.
In some amount of time(At most a couple seconds) the memory being used up by that part will be removed or ‘freed’ to be used by something else.

1 Like

I see, but I’m developing an anti cheat and, just thought of this, since ipairs skips over nil, when an exploiter would iterate through gc with ipairs, I could stop the exploiter from reaching a point. While this is easily by-passable by simply using pairs instead, it would be a cool POC.

However, since nil can technically have a reference to it (right?), it can be “de-referenced” and end up within the gc.

Note that gc is a table (when grabbed with an exploit) and thus can “contain” things - usually userdata, tables and functions.

Please correct me if I’m wrong, this is based upon loose knowledge and reading exploit docs.

2 Likes

I don’t have knowledge of the complete inner workings of normal Lua(Let alone roblox’s version)

The gc doesn’t store the variables it collects as this would defeat the purpose.
It removes the unused memory if it saved the references they would still use up memory which would make it near useless.
Anything collected by the gc is gone forever.
Even if it did store the references they would be useless as they would just be nil.
So worrying about it is..well don’t.

Edit: It may be that the gc is a table when grabbed with a exploit but the only thing stored within it would be the functions regarding garbage collection(If roblox hasn’t just straight up deleted them)

1 Like