Jump to content

Quick LUA question


Alienhead
 Share

Recommended Posts

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.

  • Like 1

I'm only happy when I'm coding, I'm only coding when I'm happy.

Link to comment
Share on other sites

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.

  • Like 3

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...