堆内存在 chrome 中的每个页面加载中增加

Heap memory increasing in each page load in chrome

我是getting aw snap or sometimes not enough memory problem when I reload my WebGL page。我有一个在 unity3d 中开发的空 WebGL 项目(只有一个摄像头 + 灯)。我正在重新加载它,并分析它的内存。

如您所见,第一次加载 1.2MB,第二次加载 1281MB,然后是 1574,然后是 2160,然后崩溃。我很惊讶为什么会这样?

我搜索并 found

一位 Unity 小伙伴 told,当浏览器 Dev Tool 打开时,每次重新加载页面都会增加内存: “

One point to note is that when profiling memory usage on page reloads in Firefox, make sure to have the Firefox web console (and debugger) window closed. Firefox has a behavior that if web console is open, it keeps the Firefox JS debugger alive, which pins all visited pages to be cached in memory, never reclaiming them. Closing the Firefox web page console allows freeing the old pages from memory

但是

我的测试表明 Chrome 是正确的,但 firefox 不是。无论您的开发工具是打开还是关闭,Firefox 都会在每次重新加载页面时增加内存。

但是我的问题在 chrome 中解决了(仍然是关于 firefox 的问题?我猜这是浏览器的默认行为),关闭开发工具后内存不会在 chrome 上增加。

问题

webgl 构建 运行 在每个桌面浏览器和 firefox 移动设备上都很好,但在使用 chrome 移动设备或带有“aw, snap”页面的 safari 移动设备时 3 秒后崩溃。

问题在于项目用于加载资产的 RAM 量。 我发现主要问题是加载音频系统。

游戏开始时,RAM 使用量从 300 MB 迅速增加到 1.3GB。

我是怎么修复的

我有一段 20 分钟长的背景音乐,我把它剪成了 5 分钟。 单击音乐,然后单击覆盖 webgl 设置加载类型为 Streaming 将质量设置为 1

使用此解决方法,RAM 使用量浮动在 600 MB 左右,这允许构建 运行 在移动设备上。

this is an example