Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      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

Happy Holidays from the GTANet team!

Memory Leaks! [C#]


NModds
 Share

Recommended Posts

Hi all,

 

I think my code is causing memory leaks and crashing GTAV with repeated use, sometimes with game memory error and others without. I have read online that one of the main causes to programs crashing is memory leaks and people had many suggestions for solving such an event. One of them was a memory profiler. I looked online for a c#-dll memory profiler and really couldn't find anything that worked for a class library. Is there a way to detect memory leaks for GTAV scripts?

Link to comment
Share on other sites

I don't know about C# memory leak, but did you check you hook log file to see what happened exactly?

ScriptHookVDotNet and RagePluginHook generates log file on crash with the detail of the exception that has been raised.

Link to comment
Share on other sites

I don't know about C# memory leak, but did you check you hook log file to see what happened exactly?

ScriptHookVDotNet and RagePluginHook generates log file on crash with the detail of the exception that has been raised.

 

When I first started getting the crash, I did check and scripthookdotnet log, but it didn't write anything. So I assumed that scripthookvdotnet didn't have time to find the error because the game crashed prematurely. But just to make sure I will try and reproduce the error and see what scripthookdotnet's log states.

Link to comment
Share on other sites

Be careful, if you restart ScriptHookVDotNet (restarting the game or using the "Inser" key), it will reset the log file. You need to check it as soon as the mod has crashed or right after exiting the game ;)

Link to comment
Share on other sites

Be careful, if you restart ScriptHookVDotNet (restarting the game or using the "Inser" key), it will reset the log file. You need to check it as soon as the mod has crashed or right after exiting the game ;)

I recreated the error, sadly Scripthookvdotnet didn't catch any errors nor Scripthook.log. I just get a message saying gta5 crashed, gives me an option to debug. when I click on debug, it states that an unhandled Microsoft .net framework exception was raised in gta5.exe. I notice that when I want to do a great deal of manipulation on different # of lists the game crashes, which is why I thought something is adding up and compounding to affect memory but I'm not sure with my current understanding of memory handling in gta5. I was also thinking that it could be caused by CPU processing time. Since I am trying not to deplete fps I request scripthookvdotnet to give me a list of peds/objects/vehicles within maybe a 1-10 millisec window and immediately try to manipulate them. But I know even less about CPU, so I'm just aiming wildly trying to find the answer.

Edited by nm710
Link to comment
Share on other sites

If the game is crashing, it can comes from a ScriptHookV (asi) script that crash or from your ScriptHookVDotNet script that runs through an infinite loop (or a loop that is too long and that doesn't have Script.Yield() or .Wait()).

I suggest you write a line into a log file at the beginning and the end of your heavy loop to see if the problem really comes from here.

Also, if you store Peds, Vehicles, etc, try to loop through your list and remove the elements if Entity.Exists() == false

I don't think it is a memory leak problem linked to C# but you should be able to check the memory usage if you open windows task manager (performance tab) and put it on a second screen or on the same screen with the game in windowed mode.

Edited by Bob_74
Link to comment
Share on other sites

If the game is crashing, it can comes from a ScriptHookV (asi) script that crash or from your ScriptHookVDotNet script that runs through an infinite loop (or a loop that is too long and that doesn't have Script.Yield() or .Wait()).

 

I suggest you write a line into a log file at the beginning and the end of your heavy loop to see if the problem really comes from here.

 

Also, if you store Peds, Vehicles, etc, try to loop through you list and remove the elements if Entity.Exists() == false

 

I don't think it is a memory leak problem linked to C# but you should be able to check the memory usage if you open windows task manager (performance tab) and put it on a second screen or on the same screen with the game in windowed mode.

Ok, thanks. I will try your suggestions and report back.

Link to comment
Share on other sites

I manged to find one case that always crashed the game. A blachole kind of power. A list of props in which I pull them to a vector position and delete the prop when the get close to the vector3 then remove them from the list. This crashed the game after 4+ use. Removing props that satisfy !Prop.Exists() helped reduce the time of crash, but interestingly the wait() function I think made it crash faster, after 2-3 attempts of using the power. After several iteration of changing the code, and several crashes later I got rid of the Prop.delete() function from my script and instead changed it to Prop.Position = Vector3.Zero and then remove it from the list, letting gtav handle the deleting of the props. I believe this has solved the problem since I haven't got any crashes despite the fact that I increased the radius of list collection. There are still crashes that occur but those are random and they take place after an hour - 2 hour use. Thanks again :).

 

 

 

 

Link to comment
Share on other sites

That's a bit odd, the game should handle Prop.delete() without any issue.

 

If you end up teleporting the props instead of deleting them, do you remove the persistence and tag the prop as no longer needed?

Otherwise the game may not delete the props by itself.

Entity.IsPersistent = false;Entity.MarkAsNoLongerNeeded();
Link to comment
Share on other sites

I didn't add it because I thought we add MarkAsNoLongerNeeded() if we created the Entity, and not when it's already present in the game and that IsPersistent by default is false. But since there is no harm in adding it, I will add it. I also found it odd that Prop.delete() caused a consistent crash, since I use that function for objects that I created.

Edited by nm710
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.