#High Ram Memory Usage
1 messages · Page 1 of 1 (latest)
Wdym?
by comparing snapshots from the start and after yeah?
No snapshots. You can see a graph of the last hundred frames or so in the profiler.
got it
The snapshots are from the dedicated memory profiler, not the regular profiler.
but object pooling shoudnt be an issue when stopping playmode, every object is destroyed
Or maybe not. I think you had to take snapshots in the regular profiler too to see the details.🤔
No. In this case it would remain, as empty heap space is basically what unity reserves from the system. Even if that memory is empty.
It would use it to allocate other stuff.
Basically, these 12 gb represent the peak of your memory consumption in the editor.
ok I create massive planets with loads of trees which i activate deactivate
this is on edit mode
Yeah, in this case there's nothing surprising.
how do I optimse that process then to avoid that massive memory usage?
object pooling
I guess
For starters, if you're only worried about the game itself, you should profile the build.
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.
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.
Also if you create any UnityEngine.Objects (Mesh, Texture, SO...) at runtime, those need to be destroyed too or you get a leak
But unity doesn't destroy them when stopping playmode?
Yeah it does, do the leaks happen between playmode sessions? Sorry didnt read the whole thing, just chimed in
Even if it does destroy, it would work towards that peak memory consumption, left as the empty heap memory.
Yeah , the editor is idle
Basically, you need to profile your game properly. Before play more, during and after exiting.
No way to tell unity please leave that memory alone, you don't need it anymore
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.
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
Actually im not even sure if it releases everything when exiting playmode. I always manually delete any leftover UnityEngine.Objects in OnDestroy or something
Like if a script creates a mesh, it is responsible for destroying that mesh too
Yeah, it's possible that it's not destroyed
What could go there?
How do I make sure they are destroyed when stopping playmode?
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); } } }
What can that be tracking?
Also if you do a lot of recompiling while in playmode, non-serialized values will be lost so that might lead into some leaks
That's impossible unless I use fast script reloading
On playmode you cant recompile
If you make changes on a script it will recompile after you exit playmode, or hit refresh
Hmm? I recompile while in playmode all the time
Is this some setting? What unity version you on?
2022
You mean this?
https://hotreload.net/
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)
Lol
Feature meaning "recompile during playmode"
So maybe it's turned off for you
@main crown
Not really sure. I've only found some old post saying that they're gonna add more detailed info in the next update.
Ok gonna turn it off
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
@open turret this the snapshot at the start of the editor
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?
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
Try looking at All Of Memory tab
Also read this on memory leaks:
https://docs.unity3d.com/Packages/com.unity.memoryprofiler@1.0/manual/find-memory-leaks.html