Shenaniganizer Posted May 25, 2015 Share Posted May 25, 2015 Hi everyone, Very quickly, I'm the developer of the super punch mod for GTA V. Originally my mod was meta based then I made the switch to LUA code. I learned and wrote the LUA version of my mod in about 2 days so I'm not really that great at it yet. The script works mostly how I want it to but there's a terrible side effect: My script uses up ram until the game crashes. This isn't instantaneous, it takes a decent amount of time. Slowly going up anywhere from 2mb - 4mb per tick until a low memory warning pops up and GTA closes. I believe I know why this happens and exactly where in the script it's happening. But I have no idea how to go about putting my thoughts into code. I've looked all over and couldn't find anything that worked when I tried it. The exact issue is with the tables part of my code. It keeps creating new tables, leaving old ones and values occupying memory: player = PLAYER.PLAYER_PED_ID()playerCoord = ENTITY.GET_ENTITY_COORDS(player,true) pTable = PED.GET_PED_NEARBY_PEDS(player, 10, 1) for j,p in ipairs(pTable) do if (not p) then break end if (p) then if addForce then if ENTITY.HAS_ENTITY_BEEN_DAMAGED_BY_ENTITY(p, player, true) then useTheForce(playerCoord, p) addForce = false break end end if not addForce then break end endend vTable = PED.GET_PED_NEARBY_VEHICLES(player, 1) for k,v in ipairs(vTable) do if (not v) then break end if (v) then if addForce then if ENTITY.HAS_ENTITY_BEEN_DAMAGED_BY_ENTITY(v, player, true) then useTheForce(playerCoord, v) addForce = false break end end if not addForce then break end endend If you would like to see the whole script you can download it from here. I just need to know how to clear the tables and their values from memory. I don't know how and I can't seem to find any information on how to do so. I've tried setting the tables values to nil but that didn't do anything, maybe I did it wrong. If anyone could help me I'd seriously appreciate it, this is a thorn in my side I desperately need removed. Thank you all for your time. Link to comment Share on other sites More sharing options...
Tiryll Posted May 25, 2015 Share Posted May 25, 2015 Are you repopulating the ptable and vtable every tick? if so then that's your problem. You need to delay how often those get repopulated and move them out of the tick function and into its own, so your loops do what they need to do, but not constantly with new information. That's what I discovered when my ram was hitting 99% usage - but I knew that was a bad practice, it's just good for testing. xD I also added in some things that adjust how much the delay is, because if you're on foot there's not as much new information as say moving in a car. Link to comment Share on other sites More sharing options...
Shenaniganizer Posted May 25, 2015 Author Share Posted May 25, 2015 Are you repopulating the ptable and vtable every tick? if so then that's your problem. You need to delay how often those get repopulated and move them out of the tick function and into its own, so your loops do what they need to do, but not constantly with new information. That's what I discovered when my ram was hitting 99% usage - but I knew that was a bad practice, it's just good for testing. xD I also added in some things that adjust how much the delay is, because if you're on foot there's not as much new information as say moving in a car. Thank you for your speedy reply! I believe I understand what you're saying. If I do that will the tables still be kept in memory, just less often or does moving them to their own function do something about that? I thought I tried something like that before but maybe I forgot something. I'll test this now. Link to comment Share on other sites More sharing options...
Tiryll Posted May 25, 2015 Share Posted May 25, 2015 Well, I believe lua has automatic garbage collection, but even so, a quick check to see if the entity still exists, if not, set it to nil and bob's your uncle. function mod.repop() ptable = .. vtable = ..endfunction mod.tick().. other code ..if(mydelay == 0)then mod.repop() mydelay = 125endmydelay = mydelay - 1end I have barely done much reading with regards to lua, but something like this stopped the performance issues. Link to comment Share on other sites More sharing options...
Shenaniganizer Posted May 25, 2015 Author Share Posted May 25, 2015 (edited) HUZZAH! I ran my script and watched the ram closely. It uses almost zero ram now, LOL! Thank you so much for your help, it was the combination everything you suggested that worked. Of course I tried all those but individually, at different times, incorrectly. Figures Now this mod can get finished, and it's all thanks to you EDIT: So it still uses increasing memory, but very slowly. I think I'm just missing a few nils as I've got it to improve each time slightly. Although I'm sure every single value I have has been nil'd out at this point... Edited May 25, 2015 by Shenaniganizer Link to comment Share on other sites More sharing options...
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