Skip to content

fix: 修复 ScriptCat 长时间运行时可能出现的内存泄漏问题#1401

Merged
CodFrm merged 1 commit intomainfrom
fix/memory-leakage/001
May 6, 2026
Merged

fix: 修复 ScriptCat 长时间运行时可能出现的内存泄漏问题#1401
CodFrm merged 1 commit intomainfrom
fix/memory-leakage/001

Conversation

@cyfung1031
Copy link
Copy Markdown
Collaborator

Checklist / 检查清单

  • Fixes mentioned issues / 修复已提及的问题
  • Code reviewed by human / 代码通过人工检查
  • Changes tested / 已完成测试

Description / 描述

变更内容

  • 为 UrlMatch URL 匹配缓存增加 4096 条 LRU 上限,避免浏览大量不同 URL 后缓存无限增长。
  • 增加 UrlMatch 缓存上限回归测试。
  • 修复 GM_xmlhttpRequest 完成或失败后未断开消息连接的问题,避免周期性请求长期累积无效监听器。
  • 清理 GM_xmlhttpRequest 网络错误等待 map,避免异常/超时路径残留 promise 引用。

Screenshots / 截图

@CodFrm
Copy link
Copy Markdown
Member

CodFrm commented May 6, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 旨在修复 ScriptCat 在长时间运行、频繁浏览/请求场景下可能出现的内存泄漏与资源累积问题:一方面限制 URL 匹配缓存规模避免无限增长,另一方面在 GM_xmlhttpRequest 的异常/完成路径上补齐连接与等待态引用的清理,减少无效监听器与 Promise 引用残留。

Changes:

  • UrlMatch 的 URL 匹配缓存增加默认 4096 条的 LRU 上限,并在命中时刷新最近使用顺序。
  • 增加 UrlMatch 缓存上限与 LRU 行为的回归测试。
  • 在 GM_xmlhttpRequest 相关实现中补齐 nwErrorResultPromises 清理,并确保 content 侧连接在清理时断开以避免长期累积。

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/pkg/utils/match.ts UrlMatch 引入带上限的 LRU 缓存,避免缓存随不同 URL 访问无限增长
src/pkg/utils/match.test.ts 新增缓存上限与“最近使用刷新”的回归测试用例
src/app/service/service_worker/gm_api/gm_xhr.ts fetch 策略等待网络错误结果后删除 nwErrorResultPromises 条目,减少残留引用
src/app/service/service_worker/gm_api/gm_api.ts 在请求结束/异常清理路径中补齐 nwErrorResultPromises 的删除,避免 map 长期堆积
src/app/service/content/gm_api/gm_xhr.ts 在清理函数中确保断开 connect,并在 code=-1 错误路径上避免重复完成导致的资源残留

@CodFrm CodFrm merged commit 72f5e93 into main May 6, 2026
8 checks passed
@CodFrm CodFrm deleted the fix/memory-leakage/001 branch May 6, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants