Memory leak issue

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

It’s almost impossible to produce an actual memory leak in Unity without messing around with native code allocation. In managed code all memory is managed. Memory that isn’t longer referenced will eventually be garbage collected automatically. No managed memory can leak that way. However Unity is not a managed application. There might be objects you have allocated that Unity sill has a reference to which you did not tell Unity to get rid of. Those are not memory leaks since you can still access all those objects. Common errors are constantly creating new Mesh, Texture2D, Material, ScriptableObject instances an never destroying them. Those won’t destroy themselfs. They are all tracked standalone objects.

Note that accessing renderer.material or Meshfilter.mesh will create an object specific duplicate of the material / mesh. If you do that on objects which are instantiated / destroyed every time they will get left behind.

One way that might help in most cases is calling Resources.UnloadUnusedAssets from time to time. Though you generally should keep track of what objects you create (direct or indirect) and destroy them when no longer in use. Note that components on gameobjects are not standalone objects. Their lifespan is bound to the gameobject they belong to. Also destroying a gameobject will destroy all child gameobjects as well. However if those might reference other standalone resources which got duplicated, you have to take care of them since you created them through code.

In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in such a way that memory which is no longer needed is not released. A memory leak may also happen when an object is stored in memory but cannot be accessed by the running code.

Maybe use the deep profiler to locate where you get the memory leak.