Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
      4. Frontier Pursuits
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. DLC
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
      7. The Diamond Casino Heist
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA IV Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA SA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA VC Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA III Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

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

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

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

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

    2. Forum Support

    3. Site Suggestions

Sign in to follow this  
Shenaniganizer

Having issues with LUA code using increasing amounts of RAM

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.

Share this post


Link to post
Share on other sites
Tiryll

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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Tiryll

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.

Share this post


Link to post
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

Share this post


Link to post
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.

Sign in to follow this  

  • 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.