#High Ram Memory Usage

1 messages · Page 1 of 1 (latest)

simple marten
#

but changing scenes out of play mode would solve this no?

#

High Ram Memory Usage

open turret
#

Wdym?

simple marten
#

by comparing snapshots from the start and after yeah?

open turret
#

No snapshots. You can see a graph of the last hundred frames or so in the profiler.

simple marten
#

got it

open turret
#

The snapshots are from the dedicated memory profiler, not the regular profiler.

simple marten
#

but object pooling shoudnt be an issue when stopping playmode, every object is destroyed

open turret
#

Or maybe not. I think you had to take snapshots in the regular profiler too to see the details.🤔

open turret
#

It would use it to allocate other stuff.

#

Basically, these 12 gb represent the peak of your memory consumption in the editor.

simple marten
#

ok I create massive planets with loads of trees which i activate deactivate

#

this is on edit mode

open turret
simple marten
#

how do I optimse that process then to avoid that massive memory usage?

#

object pooling

#

I guess

open turret
#

For starters, if you're only worried about the game itself, you should profile the build.

simple marten
#

the game is ok

#

is the editor

open turret
#

If you want to troubleshoot the editor, I'm not sure if there's much you can do.
Aside from reducing the peak of memory consumption.

#

Pooling might help depending on your setup.

simple marten
#

How to reduce the peak?

#

Ok

#

Thank you man, that was really helpful

open turret
#

Basically, don't spawn/instantiate a lot of stuff at the same time.

#

I don't know if you have a memory leak or something, but if you do, that might explain things.

frigid crow
#

Also if you create any UnityEngine.Objects (Mesh, Texture, SO...) at runtime, those need to be destroyed too or you get a leak

simple marten
frigid crow
#

Yeah it does, do the leaks happen between playmode sessions? Sorry didnt read the whole thing, just chimed in

open turret
#

Even if it does destroy, it would work towards that peak memory consumption, left as the empty heap memory.

open turret
#

Basically, you need to profile your game properly. Before play more, during and after exiting.

simple marten
open turret
#

Restart the editor I guess 🤷‍♂️

#

I don't know if there's any editor API that could help here. It's not like that memory is occupied. It's just reserved.

#

Though the untracked memory is a bit worrying as it's taking the biggest chunk of the whole memory.

simple marten
#

Yeah electricity went off at home , gonna check before and after and I suspect it maybe because those damn 1000 trees spawned, even if they are deactivated

frigid crow
open turret
#

Yeah, it's possible that it's not destroyed

simple marten
frigid crow
#

If a script creates something, it should hold a reference to it

#

And then Destroy that object when it dies itself

#

Just as an example...cs public class MeshMaker : MonoBehaviour { Mesh mesh; void Start() { mesh = new Mesh(); /* ... */ } void OnDestroy() { if(mesh != null) { Destroy(mesh); } } }

frigid crow
#

Also if you do a lot of recompiling while in playmode, non-serialized values will be lost so that might lead into some leaks

simple marten
frigid crow
#

Wdym impossible?

#

Does it crash/freezes or something if you try?

simple marten
#

On playmode you cant recompile

#

If you make changes on a script it will recompile after you exit playmode, or hit refresh

frigid crow
#

Hmm? I recompile while in playmode all the time

#

Is this some setting? What unity version you on?

simple marten
#

2022

#

You mean this?
https://hotreload.net/

Hot Reload for Unity

Change code and get immediate updates in the Unity Editor or on-device. Built by game devs, for game devs - our studio has battle-tested Hot Reload for more than 3 years.

frigid crow
#

Nope, I mean simply saving a script while in playmode and it will just recompile it for me

#

(static and non-serialized values will be reset to default when doing this)

#

Feature meaning "recompile during playmode"

#

So maybe it's turned off for you

simple marten
#

@main crown

open turret
simple marten
simple marten
#

asking chatgpt I got this about destroying those trees @frigid crow

#

In Unity, if you want to destroy objects created during play mode when you stop play mode in the editor, you don't need to handle this manually. Unity will automatically clean up these objects when play mode is stopped. This is a built-in feature to prevent any memory leaks.

So, when you stop play mode, all temporary objects created during play mode, including those created with Instantiate or through script, will be automatically destroyed, and their memory will be released. You do not need to write additional code to handle this cleanup; Unity handles it for you.

Just ensure that the objects you want to be automatically destroyed are indeed created during play mode and not part of your scene hierarchy in the editor. Objects that are part of the scene hierarchy will persist between play mode sessions. Temporary objects created through script during play mode will be automatically cleaned up when you stop play mode, which helps prevent memory leaks.

#

there is no need to destroy those spawned trees then

#

Im gonna try to keep running a more light scene and see if the ram keeps increasing

#

in the same way

simple marten
#

@open turret this the snapshot at the start of the editor

open turret
#

Still quite weird that untracked is being almost the biggest category. I'm not really accustomed with the dedicated memory profiler, but there must be a way to see more details. Maybe the "inspect" button.

#

According to some info online, it seems like untracked includes external plugins. Are you using any kind of plugins or assets that could be allocating a lot of memory?

simple marten
#

mmm let me check them out

#

console pro 3 , odin inspector, ...

#

urp

#

it's crazy because i can see how hitting play, keeps making the ram creep up progresively

#

gonna try to do the same In a different scene

#

press play stop play stop...

#

ok If I do that in the menu scene the RAM doesnt creep up

#

Also I'm using fast script reload lately, maybe that is the reason . I uninstalled it, let's see how it works now

open turret
#

Try looking at All Of Memory tab

simple marten
#

Ok I think it has been the plug in fast script reload

#

Im gonna raise an issue on their github

#

I have been working for an hour without the asset and my ram stays under 40%

#

of 32 gb

#

@open turret

#

thank you for pointing at plug ins!

#

never thought it could be that