Jump to content

Unity memory issue


Recommended Posts



It's now been 4 days that I'm trying to fix this issue.

I'm using Wave SDK for Unity 3.0.2, and Unity 2019.1.7f1.


Basically, I have an "out of memory" issue even though there should be still a lot to spare.

It only happens when I'm switching from a scene to another, but not all the time. The only mandatory part is for the new scene to be larger in memory than the previous one.

Sometimes it's an OpenGL ES error "GL_OUT_OF_MEMORY". Sometimes an Android one "Could not allocate memory: System out of memory!"

Here is some more info from the Android one:

[ ALLOC_DEFAULT ] used: 559739971B | peak: 1137576874B | reserved: 575390594B
[ ALLOC_TEMP_JOB_1_FRAME ] used: 0B | peak: 0B | reserved: 1048576B
[ ALLOC_TEMP_JOB_2_FRAMES ] used: 0B | peak: 0B | reserved: 1048576B
[ ALLOC_TEMP_JOB_4_FRAMES ] used: 3090535B | peak: 0B | reserved: 11534336B
[ ALLOC_TEMP_JOB_ASYNC ] used: 0B | peak: 0B | reserved: 1048576B
[ ALLOC_GAMEOBJECT ] used: 1681104B | peak: 2817667B | reserved: 1691554B
[ ALLOC_GFX ] used: 6388369B | peak: 400481140B | reserved: 6398078B
[ ALLOC_TEMP_THREAD ] used: 105416B | peak: 0B | reserved: 3440640B


We can quickly determine that it doesn't have to go over 2GB total to happen.


The OpenGL issue doesn't actually make the application crash, but the image displayed from that point on could be best described as "funky". It can disappear if you manage to leave the current scene for a lighter one though.


In the meantime, Unity Profiler shows a "Total System Memory Usage" really close to 3.5GB. Sometimes going over it, without crashing the app. But most of the time it does. And the "Reserved total" is well below 3.5GB. Usually around 1.2GB.

My money would be on an unsafe threaded concurrent memory call.


I'm suspecting the camera rendering to be the issue.

Basically the camera from the previous scene is deleted, and a new one is created.

I tried having a "no current camera" gap between the two. Having no gap at all, or at least, the closest I could manage since so much is threaded. Disabling Multi Threading or Graphic Jobs didn't do anything. I tried every Unity graphics option actually.

And I tried overlapping the two cameras.

In every scenario, that message always appears:

[EGL] Unable to acquire context: EGL_BAD_SURFACE: An EGLSurface argument does not name a valid surface (window, pixel buffer or pixmap) configured for GL rendering.
(Filename: ./Runtime/GfxDevice/egl/WindowContextEGL.cpp Line: 287)

Whether it crashes or not.


What I will test next is to reuse the same camera throughout all the scenes. Hopefully it should work!


I haven't tried Unity 2018 back yet, but I really hope I don't have to. I have one other last test as well, which is to move from ETC2 to ASTC texture compression, which I'll normally be able to test tomorrow.


Has anyone encountered something similar?

I'd really appreciate if you have, and could comment :)




  (tag added by forum moderator)

Link to comment
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
  • Create New...