cheez3d Posted June 16, 2014 Share Posted June 16, 2014 (edited) 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 June 16, 2014 by Guest Link to comment
Johnny Killstone Posted June 16, 2014 Share Posted June 16, 2014 I think lua is based on C so you won't need stuff like garbage collections, that's more of a java feature, all variables in lua are pointers which you can set to nil to free some space in your memory, also in general MTA servers doesn't seem to consume much RAM at all so no need to worry about "garbage". Link to comment
cheez3d Posted June 16, 2014 Author Share Posted June 16, 2014 The idea is I can't set the pointer to nil. I'd do so if I could. That's why I needed the metamethod. Link to comment
Johnny Killstone Posted June 16, 2014 Share Posted June 16, 2014 local variable = 45 variable = nil Simple as that? Link to comment
DiSaMe Posted June 16, 2014 Share Posted June 16, 2014 In 5.1, only metamethod for userdata is mentioned: http://www.lua.org/manual/5.1/manual.html#2.10.1 In 5.2, metamethod is used for both tables and userdata: http://www.lua.org/manual/5.2/manual.html#2.5.1 Which means you can't do it in 5.1. Link to comment
ixjf Posted June 16, 2014 Share Posted June 16, 2014 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. 1 Link to comment
arezu Posted June 16, 2014 Share Posted June 16, 2014 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
cheez3d Posted June 16, 2014 Author Share Posted June 16, 2014 I guess I'm going to use the weak values then. Thank you for your responses. 1 Link to comment
johnsonjeven Posted December 12, 2017 Share Posted December 12, 2017 More on ...Java Memory Management Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now