Closed xmsuperman closed 1 year ago
可以确认内置的plot组件存在内存泄露
通过修改原码,可以极大的延缓内存溢出的时间,但是经测试300+以后还是会内存溢出。
1327行 将OffscreenCanvas对象全局化, this.offscreenCanvas = new OffscreenCanvas(512, 512);
1331行 创建create3DContext使用全局化的offscreenCanvas if (create3DContext(this.offscreenCanvas, { premultipliedAlpha: false }) !== null) {
在destory方法中增加以下代码 if(this.ctx){ this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); }
this.gl = null;
this.offscreenCanvas = null;
this.ctx = null;
this.canvas = null;
this._source = null;
将TIFFImageryProvider的destory增加
this._workerFarm = null;
this.plot = null;
将WorkerFarm的destory方法增加
this.worker = null;
元凶找到,按照作者的指导,修改 1331行 原 if (create3DContext(new OffscreenCanvas(512, 512), { premultipliedAlpha: false }) !== null) { const gl = create3DContext(this.canvas, { premultipliedAlpha: false }); 新 const gl = create3DContext(this.canvas, { premultipliedAlpha: false }); if (gl!==null) {
彻底解决问题
出现 WARNING: Too many active WebGL contexts. Oldest context will be lost.
然后出现 TypeError: Cannot read properties of null (reading 'createShader')
at createProgram (index.js:1122:1) at new plot (index.js:1334:1) at TIFFImageryProvider.eval (index.js:2156:1) at Generator.next ()
at fulfilled (index.js:22:1)
`let i = 0; window.setInterval(async () => {