Unity keeps creating texturt and eventually leads to insufficient memory webgl

Unity keeps creating texturt and eventually leads to insufficient memory webgl

Problem occurrence and resolution process

In the recent webgl project, after the program was modified, the packaged webgl program had a memory overflow problem. This situation did not occur in the Editor. When running the profiler in the editor, I found that the occupied memory is constantly increasing. A closer look shows that the number of Textures is constantly increasing, causing the memory usage to increase.
Insert image description here
So during runtime, by setting each gameobject to Inactive, the gameobject that caused the problem was found.
Insert image description here

After checking the executed code, I found that new textures were continuously created and used in the update function without releasing the old created textures. Finally, the function was optimized and the memory overflow problem was solved.

Summarize

When you encounter this type of error after running for a period of timeInsufficient memory, you can try to check the Profiler first to see which part appears. Remove the accumulated useless resources, and then modify the active of Gameobject at runtime to locate which module is repeatedly creating resources, then locate the corresponding code, and finally modify the code.
If it cannot run from the beginning, it needs to be optimized to reduce the memory required at runtime to less than 2GB.

date

2023.05.06

Guess you like

Origin blog.csdn.net/wjm_hmj/article/details/130523980