【问题标题】:How to clean up textureCache A-frame at current version?如何清理当前版本的 textureCache A-frame?
【发布时间】:2021-05-18 16:31:36
【问题描述】:

我正在开发一个多摄像头流媒体应用程序,我注意到切换摄像头后内存使用量不断增加。我在 hls.js 方面进行清理。但我没有看到任何方法可以在框架中做到这一点。 我正在使用 1.2.0

我只找到推荐的旧帖子
document.querySelector('a-scene').systems.material.textureCache 并运行.dispose()

这看起来像是在 0.3.0 版本上工作的,但从那以后就没有了。

有没有办法清理纹理,或者这现在是自动发生的?

【问题讨论】:

    标签: javascript three.js aframe hls.js


    【解决方案1】:

    Afaik textureCache 是一个在加载纹理时信守承诺的对象(imagevideo)。

    有一个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>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-11
      • 2014-01-27
      • 1970-01-01
      • 2016-07-16
      • 2018-07-21
      • 1970-01-01
      相关资源
      最近更新 更多