Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Are custom objects able to be marked for garbage collection?

Asked by
SteamG00B 1633 Moderation Voter
4 years ago

So for fun, I've been tinkering with compression algorithms in lua, and in order to make things easier for myself, I've also created a module script that acts like a doubly linked list that stores key value pairs (so basically a dictionary that acts like a doubly linked list).

So what my question is about is: when I am finished using a linked list or a chain of nodes, is there anything I need to do to mark each node or whole list for garbage collection besides removing references to each node?

1 answer

Log in to vote
2
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Read into it a bit, and the website I was reading from said the following:

Because of garbage collection...no need to free them when no longer needed except for setting it to nil. Lua uses a garbage collector that runs from time to time to collect dead objects when they are no longer accessible from the Lua program.

In C/C++ freeing node clears all it's values from memory as well - and that's without a garbage collector, so I assume ROBLOX will clear out the node's values as well acting as free() or delete() when you set the node to nil. The variables are no longer accessible since the references to the node were deleted so according to that website, they should be deleted.

0
Well from what I could read on that link, it does this with objects that are already built-in, but due to the fact that I am mostly making custom objects, if I set the previous and next nodes to nil, that would mark each node for collection, but would it also clear out references to other custom objects stored within each node is what I am unclear with. SteamG00B 1633 — 4y
0
The main part I am unsure about is how it deals with custom objects because I know how to use module scripts to make custom objects, but I am still unsure about how they are handled by the system. SteamG00B 1633 — 4y
1
yeah, the class basically acts like a table containing variables/functions/whatever. anything inside get deleted eventually when the table is deleted if there are no other references to anything inside the table. also, make sure that there's no references to the objects or gc won't collect it royaltoe 5144 — 4y
0
Alright, thanks for clearing this up for me, I guess my lack of memory is probably due to not setting the references inside each node to nil. SteamG00B 1633 — 4y
Ad

Answer this question