javascript - 如何在当前版本清理 textureCache A-frame?
问题描述
我正在开发一个多摄像头流媒体应用程序,我注意到切换摄像头后内存使用量不断增加。我在 hls.js 方面进行清理。但我没有看到任何方法可以在框架中做到这一点。我正在使用 1.2.0
我只发现旧帖子推荐
document.querySelector('a-scene').systems.material.textureCache
并运行.dispose()
这看起来像是在 0.3.0 版本上工作的,但从那以后就没有了。
有没有办法清理纹理或者这现在是自动发生的?
解决方案
AfaiktextureCache
是一个承诺加载纹理(图像、视频)的对象。
有一个clearTextureCache
功能,但它清除对象,而不处理加载的纹理。
我会尝试遍历textureCache
,抓取THREE.Texture
对象并调用.dispose()
它们。然后你可以做clearTextureCache()
清理它。在下面的示例中 - 任何单击 io 窗口都会在控制台中打印缓存的纹理:
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
<script>
AFRAME.registerComponent("foo", {
init: function() {
window.addEventListener("click", e => {
const textureCache = this.el.systems.material.textureCache;
console.log("Textures in the cache:")
for (let key in textureCache) {
textureCache[key].then(val => console.log(val))
}
})
}
})
</script>
<a-scene foo>
<a-image position="-1 1.6 -2" src="https://i.imgur.com/wjobVTN.jpeg"></a-image>
<a-image position="1 1.6 -2" src="https://i.imgur.com/AD3MbBi.jpg"></a-image>
<a-sky color="#ECECEC"></a-sky>
</a-scene>
推荐阅读
- python - 如何将 defaultdict 转换为 pandas 数据框
- html - 图像文本后的引导卡图像不可见区域
- python-3.x - 如何在另一个模块中设置全局变量?
- sql - 加入或多个sql查询
- r - R通过带边距的向量或一个角度的边界框过滤GPS数据集
- javascript - 如何删除待办事项列表中的列表项
- python - 独角兽工人卡住了
- node.js - Node JS decipher.final() 抛出“错误的最终块长度”错误
- ios - 在 Swift 中动态实例化 ObjC 类(使用 NSClassFromString?)
- c# - Microsoft Access 数据库引擎 2010 或 Microsoft Access 数据库引擎 2016 以读取 Excel 文件?