Alienhead Posted August 30, 2022 Share Posted August 30, 2022 I'm cleaning up some possible mem leaks and wanted to know if the following code inside a normal Function/End could be a possible memory leak. ---Check human list --- for r, m in pairs ( serguard ) do if chkAggression(s.myRace, mobdef[m.entity.script.id].race) then The R and the M. Inside the function they are not declared local. Do these variables drop off to GC() after losing scope or are they passed as globals and remain in memory.. I have tons of for/next loops with unlocalized variable usage like the above.. Should I go back and localize them all or do they drop ? Thanks. 1 Quote I'm only happy when I'm coding, I'm only coding when I'm happy. Link to comment Share on other sites More sharing options...
Josh Posted August 31, 2022 Share Posted August 31, 2022 Those are globals so they never go out of scope, but they will only consume one variable's worth of memory. You should not worry about memory management in Lua much because it aggregates memory until a threshold is reached, and then runs the garbage collector automatically. You could continuously call collectgarbage() yourself, but it would slow down your framerate. Maybe call it after loading a scene. In Ultra, since game logic runs independently from the renderer, you can call collectgarbage() once per loop if you wish and in normal circumstances it will have no effect on the framerate, since your code has a full 16 milliseconds to run. 3 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.