A memory leak in the store.js file has been reported, where the _identityMap grows rapidly with each RESTful request as users navigate between topics, leading to excessive memory consumption. small-lovely-cat observed the heap size increasing from 100MB to 500MB after repeated navigation, with memory not being released upon returning to the homepage. They suggested implementing a pruneMap function using a FIFO algorithm to clean up old entries. zogstrip asked for more data, prompting small-lovely-cat to provide test results, a video demonstration, and a screenshot showing the growing map size. The issue is acknowledged, and saquetim references a PR (https://github.com/discourse/discourse/pull/37163) that aims to resolve the memory leak.
There seems to be a memory leakage in store.js file, when users browses through different topics, the _identityMap seems to be growing rapidly with each restful request. Without a proper cleanup logic, the map will exhaust memory with large js heaps.
Maybe adding a pruneMap function to the store.js, with FIFO algorithm to remove the earliest maps will be enough?
Reproduce steps is like the following: user skips from one topic to another using the “suggested/related” under the topic for multiple times without refreshing the page, and the js heap size will accumulate from the original 100MB to about 500MB in my test, if visited topics are enough(especially for topics with much posts under it). And returning to the homepage won’t release that part of occupied memory.
This js heap size can be seen from the browser console-performance, and the memory consumption can be seen from the process manager of the browser.
I uploaded a video of this attached in the PR, just showcase the problem(about 3 mins, when using the same page for more hours, the situation will be worse)
And also adding a breakpoint here will showcase the growing amount of items in _identityMap