Jump to content

[SOLVED] Garbage Collection


cheez3d

Recommended Posts

Does Lua 5.1 support the __gc metamethod for tables? I looked on the internet and found out that Lua 5.2 supports it. I tried to see if it works on MTA, but unfortunately it doesn't :(. The version of Lua MTA uses is 5.1.

Edited by Guest
Link to comment
I think lua is based on C so you won't need stuff like garbage collections, that's more of a java feature, [...] also in general MTA servers doesn't seem to consume much RAM at all so no need to worry about "garbage".

What are you talking about? Lua is written in, not based on C. It's a managed, interpreted language (just like Java, unlike C/C++). It has a garbage collector, and it is there for a reason - to collect any data that can no longer be accessed (not referenced anywhere). Most of the times you don't need to worry about the garbage collector, it does its work, you do your work, and everyone is happy, but you can control it through the collectgarbage function if you need to.

all variables in lua are pointers which you can set to nil to free some space in your memory,

It's a managed language, you don't work with pointers directly.

  • Like 1
Link to comment

What are you trying to do? free memory that lua variables use? set the variable to nil (if it is a table, you will need to set all references to the table to nil), and lua will free it when it best fits.

You can also use "collectgarbage" lua function to change the behavior of the garbage collector, and you can change keys in tables to be weak keys, so they may automatically be free'd and refilled when lua sees it fits.

Link to comment
  • 3 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...