Jump to content
  • Advertisement
Gautti

Gameplay Increasing Ram of the System by playing the game continuously

Recommended Posts

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

 

 

Share this post


Link to post
Share on other sites
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

 

Share this post


Link to post
Share on other sites
12 hours ago, Gautti said:

when tester play the game continuously for 5 to 10 hours

Good tester :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Posted (edited)
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 ?

Edited by Gautti

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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().

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Posted (edited)

@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

Edited by Wyrframe

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!