多次运行后javascript崩溃

发布于 2025-01-02 05:06:25 字数 507 浏览 2 评论 0原文

我有一个 WebGL 画布,其中包含大约 90k 个顶点,然后是一些“活动”文件,这些文件基本上告诉每个“时间步骤”每个顶点应该具有什么颜色。该活动被分成多个“块”,每个块存储在一个单独的文件中。在一个文件的活动结束后,我会读取新的活动,如下所示:

    activitiesData = null;
    activitiesData = nextActivitiesFileData.slice(0);

这里 nextActivitiesFileData 由 ajax 调用异步读取。现在,所有这些在第一次运行时都可以正常工作,有时甚至可以进行更多运行,但在第二次运行时 -> 就可以了。第十次运行间隔它崩溃了。 现在我认为这是因为所使用的非常大的数据在某种程度上被垃圾化的速度不够快。我尝试始终小心地使用 var 并将不需要的数组分配给 null

我能做些什么来尝试“帮助”垃圾收集过程吗?这次事故可能还有其他性质吗?

I have a WebGL canvas that contains somewhere around 90k vertices and then some 'activity' files which basically tells at each 'time step' what color should every vertice have. This activity is splitted in a number of 'chunks' each stored in a separate file. After the activity from one file has past, I read the new one like:

    activitiesData = null;
    activitiesData = nextActivitiesFileData.slice(0);

Here nextActivitiesFileData is asyncronously read by an ajax call. Now all this works fine at first run, and sometimes even for some more runs, but somewhere along the 2nd -> 10th run interval it crashes.
Now I assume this is due to the fact that the very large data that are used are somehow not garbaged fast enough. I've tried to be carefull always to use var and assigned not needed arrays to null.

Is there anything I can do to try to 'help' the garbage collection process? Could this crash be of any other nature?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒儿 2025-01-09 05:06:25

如果我理解你的问题,你是否遇到过 GPU 上的数据释放速度不够快的问题?

有两种方法可以释放 WebGL API 分配的内存。
如果您通过 gl.createBuffer() 创建一个 WebGLBuffer 对象,则仅当 javascript 对象被垃圾收集时(不再有对该对象的任何引用),实际的缓冲区才会自动释放,但这个过程很难预测。

根据最新规范 http://www.khronos.org/registry /webgl/specs/latest/#5.14.5,大多数 WebGL 对象类型都有“删除器”,以便程序员更好地控制内存。
当您不再需要缓冲区时,请尝试调用 void deleteBuffer(WebGLBuffer? buffer) 方法。

但是,如果您万一遇到 CPU 端内存不足的问题,我对这个不相关的答案表示歉意。

If I understand your question, you have the problem with data on the GPU not being freed fast enough?

There are two approaches to freeing memory allocated by the WebGL API.
If you create a WebGLBuffer object via gl.createBuffer(), the actual buffer is automatically deallocated only when the javascript object is garbage collected (there are no longer any references to that object), but this process is very hard to predict.

According to the latest spec http://www.khronos.org/registry/webgl/specs/latest/#5.14.5, there are "deleters" for most of the WebGL object types to give the programmer greater control of the memory.
Try calling the void deleteBuffer(WebGLBuffer? buffer) method when you no longer need the buffer.

However, if you by any chance have a problem with running out of memory on the CPU side, I apologize for this unrelated answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文