ovi*_*ovi 6 reactjs redux server-side-rendering redux-saga
我正在研究一个使用redux和redux-saga的React同构应用程序.我的问题是,运行应用程序的节点进程在处理请求时会占用越来越多的内存,直到它最终耗尽内存.
我对应用程序进行了分析,node --inspect并注意到saga库一直(array)在内存中创建类型引用,即使在垃圾回收运行之后也永远无法清除.
要测试该问题,请运行此项目并使用chrome-devtools对其进行概要分析:https: //github.com/MartinCerny-awin/isomorphic-react-redux-saga-ssr
(不是我的项目,但似乎行为相同)
您可以在堆diff中看到这些对象:
updateState in system / Context @1770579 context in cancel()
我已经尝试将redux存储和saga中间件绑定到express response,认为它是一个请求命名空间问题,但这并没有解决它.
Redux saga任务取消将防止内存泄漏。
取消组件卸载/路由更改时的 SAGA
我认为问题在于,在与传奇相关的组件卸载后,您没有取消传奇。这可能会导致内存泄漏,因为传奇一直在等待操作并且不会终止。
import { LOCATION_CHANGE } from 'react-router-redux';
// other imports
function* rootSaga() {
const watcher = yield [
takeLatest(GET_TODO, getToDoSaga),
// your other sagas
];
// the saga gets cancelled when your route changes. Instead
// a custom action can also be dispatched from your
// componentWillUnMount of ToDo component
yield take(LOCATION_CHANGE);
yield watcher.map((task) => cancel(task));
}
export default [
rootSaga,
];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1047 次 |
| 最近记录: |