pengkobe / reading-notes

:stars: to record daily reading notes. I build an issue blog to record daily FE study notes. suggestion and comments are welcomed.
https://github.com/pengkobe/reading-notes/issues
MIT License
13 stars 1 forks source link

Ionic/Angular 内存泄漏 #446

Open pengkobe opened 6 years ago

pengkobe commented 6 years ago

在控制台中发现一个 window 级变量,一直持有一个 __zone_symbol__orientationchangefalse 的属性,然后引用到了被 pop 后的 ViewController,导致一直无法释放。

趣事

我在使用 ngFor 时初始化数据用到了 new Array() 导致后来内存中一直存在不能被清空,真是有趣

相关探讨

document.getElementById('result').textContent = same(); // true document.getElementById('resultBind').textContent = sameBind(); // false

我们要修复 bug,可以在目录下文件``` node_modules/ionic-angular/navigation/view-controller.js ``` 将
```javascript
window.removeEventListener('orientationchange', this.handleOrientationChange.bind(this));

修改为

window.removeEventListener('orientationchange', this.handleOrientationChange);

后续

修改后,经常会出现报错 this.getContent is not a function

  ViewController.prototype.handleOrientationChange = function () {
        if (this.getContent()) {
            this.getContent().resize();
        }
    };