-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak after upgrading from 1.9.5 to 2.4.0 #4871
Comments
Can you give an example of the overall usage patterns that you have in the app? Store creation, frequency of actions, what you're selecting? |
We would still very much like a reproduction of the situation you are seeing, but specific to a combination of SSR, default states, and selectors with primitive arguments, this repro might help to investigate: Core of that reproduction is: const slice = createSlice({
name: "slice",
initialState: {
items: [],
},
reducers: {},
});
const selector1 = createSelector(
[(fullState) => fullState.slice, (_, userId) => userId],
(userState, userId) => ({ userId }),
{
memoize: weakMapMemoize,
argsMemoize: weakMapMemoize,
}
);
for (let i = 1; i <= 500; i++) {
const store = configureStore({ reducer: { slice: slice.reducer } });
selector1(store.getState(), i);
} The problem here being that the initial state of For debugging, I ran this locally and added this line to function weakMapMemoize(func, options = {}) {
let fnNode = createCacheNode();
+ (globalThis.rootNodes ??= []).push(fnNode)
const { resultEqualityCheck } = options; Then at the end of the IIFE console.log('finished', globalThis.rootNodes)
debugger; |
Thanks for feedback, I will try to debug our code and provide more data |
Hey. We encountered a memory leak problem on server (nextjs page router) after update
redux-toolkit
from 1.9.5 to 2.4.0. After investigating the heap snapshot, we found that the problem was in the reselect (describe in reduxjs/reselect#635).A temporary fix is to use this
lruMemoize
for createSelector instead ofweakMapMemoize
. But anyway I think this information should be described in the documentation (may be in migration guide) because this is clearly not expected behavior (I mean memory leak).diagram after fallback to

lruMemoize
in 02/20:The text was updated successfully, but these errors were encountered: