# PERF：frontend-store 中似乎存在内存泄漏

**URL:** https://meta.discourse.org/t/perf-there-seems-to-be-a-memory-leakage-in-frontend-store/393510
**Category:** Bug
**Created:** [2026年一月15日 05:36 UTC](https://meta.discourse.org/t/perf-there-seems-to-be-a-memory-leakage-in-frontend-store/393510 "2026-01-15T05:36:40Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![small-lovely-cat](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/small-lovely-cat/32/553546_2.png) [@small-lovely-cat](https://meta.discourse.org/u/small-lovely-cat)
#### Post date: [2026年一月15日 05:36 UTC](https://meta.discourse.org/t/perf-there-seems-to-be-a-memory-leakage-in-frontend-store/393510/1 "2026-01-15T05:36:40Z")

</div>

在 `store.js` 文件中似乎存在内存泄漏，当用户浏览不同主题时，每次 restful 请求都会导致 `_identityMap` 快速增长。如果没有适当的清理逻辑，该映射将耗尽内存并导致大的 JavaScript 堆。

也许可以在 `store.js` 中添加一个 `pruneMap` 函数，使用先进先出（FIFO）算法来移除最早的映射就足够了？

另外，变量 `const MAX_ITEMS_PER_TYPE = 500;` 可以进一步讨论，以在缓存和内存存储之间取得平衡。

> <https://github.com/discourse/discourse/pull/37134>
>
> There seems to be a memory leakage in \`store.js\` file, when user browse through …different topics, the \`\_identityMap\` will grow rapidly with each restful request, then exhausting memory with large js heaps.
> 
> This commit adds a pruneMap function to the \`store.js\`, with FIFO algorithm to remove the earliest maps to solve this.
> 
> A video demo attached:
> 
> https://github.com/user-attachments/assets/8baad4cb-c5f9-4cdd-a608-889a3011e72d

---

_[View the full topic](https://meta.discourse.org/t/perf-there-seems-to-be-a-memory-leakage-in-frontend-store/393510)._
