Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Criminal Enterprises
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Support

    3. Suggestions

Having issues with LUA code using increasing amounts of RAM


Shenaniganizer
 Share

Recommended Posts

Shenaniganizer

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

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

Shenaniganizer

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

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

Shenaniganizer

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 :p

 

Now this mod can get finished, and it's all thanks to you :D

 

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 by Shenaniganizer
Link to comment
Share on other sites

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
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.