Increasing Ram of the System by playing the game continuously

Started by
17 comments, last by Wyrframe 4 years, 10 months ago

Hi, I have developed the  Slot game for Linux and Windows in Unity. Right now the game is in testing phase. The issue is when tester play the game continuously for 5 to 10 hours, Ram of the system increases drastically and sometimes the game is crashing.  So please give me the best way to solve the ram issue and crashing issue as well.

I am using following system configuration :

Ram :  8 GB

Processor : Ryzen 3

 

 

Advertisement

Sounds like you are having a typical memory leak issue. Since you are using Unity, you use C# as programming language which has a garbage collector. So the most obvious leaks that occur in C++ (direct use of new and delete) are off the table. However, there are other problems that can cause memory leaks, even in garbage collection systems. Since I am a C++ guy I can't help you with detailed debug instructions but you might find the following articles helpful:

https://michaelscodingspot.com/find-fix-and-avoid-memory-leaks-in-c-net-8-best-practices/

https://stackoverflow.com/questions/5020814/memory-leaks-c-sharp

 

Greetings

 

12 hours ago, Gautti said:

when tester play the game continuously for 5 to 10 hours

Good tester :)

We have had encountered a similar issue with our game where the memory increases and the game crashes in periods. The problem was caused by a pool of game objects we held in memory that partially slept there while the pool thought it is empty and started to generate new ones.

You have to explictely destroy dynamic allocated objects and all of their components to get C# to garbadge collect classes and to Unity to free up the space they take in memory

1 hour ago, Shaarigan said:

We have had encountered a similar issue with our game where the memory increases and the game crashes in periods. The problem was caused by a pool of game objects we held in memory that partially slept there while the pool thought it is empty and started to generate new ones.

You have to explictely destroy dynamic allocated objects and all of their components to get C# to garbadge collect classes and to Unity to free up the space they take in memory 

      Hi Shaarigan, Thank you so much for your answer. Can you please let me know how can we find  dynamic allocated objects and how can we destroy them In Unity C# ? ? Can you please give me a small demo ?

Every call to


GameObject instance = (GameObject)Instantiate(...);

needs a coresponding call to


Destroy(instance);

if you called


instance.DontDestroyOnLoad();

anywhere in your code or you load scenes additive but don't remove them properly if you never call a load to scenes non-additive. You can unfortunately use only the profiler to investigate such sleeping objects if you notice a memory increase out of the normal RAM fluctuation while playing the game

4 minutes ago, Shaarigan said:

Every call to



GameObject instance = (GameObject)Instantiate(...);

needs a coresponding call to



Destroy(instance);

if you called



instance.DontDestroyOnLoad();

anywhere in your code or you load scenes additive but don't remove them properly if you never call a load to scenes non-additive. You can unfortunately use only the profiler to investigate such sleeping objects if you notice a memory increase out of the normal RAM fluctuation while playing the game

               Shaarigan, In the case I am already using Destroy(instance) and I am pooling the objects. My game is running in one scene only.So i haven't used DontDestroyOnLoad().

Do you have any Material swaps, Shader exchange, procedural generated Meshes ordynamic Collider attaching/detaching?

22 minutes ago, Shaarigan said:

Do you have any Material swaps, Shader exchange, procedural generated Meshes ordynamic Collider attaching/detaching?

In my game 2D images are instantiating and pooling (Type of Slot game). I do not used shader exchange, not used procedural generated Meshes  or not ordynamic Collider attaching/detaching as well.

@Gautti: try instrumenting the problem; that is, make it possible to analyze the state of the system, so you can identify the issue.

For each of your dynamically-created object types, set up a "live object counter". Increment it every time you instantiate, decrement it every time you explicitly destroy. You'll want some interface to monitor things as well, so you can see the current counts. Watch to see if there's some particular object type which is running away on you (getting higher over time, instead of staying relatively steady or bounded).

It may also be some system resource you're acquiring and not releasing. Are you doing any kind of dynamic sound generation? Opening files and possibly failing to close them under some circumstances? Creating dynamic meshes for your objects and not destroying those separately?

 

Addendum: "slot game" doesn't really explain what it is, or what you're doing. Do you mean slot as in "slot machine", a variety of gambling? https://en.wikipedia.org/wiki/Slot_machine

RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.

This topic is closed to new replies.

Advertisement