componentWillUnmount() { setTimeout(() => { // 为什么还能看到 state 呢? console.log('componentWillUnmount', this.state); }, 5000); }
组件不是卸载了吗,为什么数据还在呢? 这是不是内存泄露了呢?
当然不算是内存泄漏了,正是因为你这里还有一个引用,所以才没有被回收。
你这里执行完了之后,就没有了引用,然后就会被回收。
正好,你其实写了一个内存泄漏的例子,console 其实就是一个内存泄漏的典型例子,虽然你代码没有引用了,但是控制台还保存着。
console
2.1m questions
2.1m answers
62 comments
56.5k users