Skip to content

fix: 修复内存泄漏(事件总线、缓存、小地图纹理重分配) - #182

Merged
gaoyu06 merged 2 commits into
mainfrom
cursor/perf-memory-leaks-9b0b
Aug 12, 2026
Merged

fix: 修复内存泄漏(事件总线、缓存、小地图纹理重分配)#182
gaoyu06 merged 2 commits into
mainfrom
cursor/perf-memory-leaks-9b0b

Conversation

@gaoyu06

@gaoyu06 gaoyu06 commented Aug 12, 2026

Copy link
Copy Markdown
Member

背景

排查用户反馈「游玩约半小时内存涨到十几 GB」。
结论:先前若干会话级泄漏量级偏小;若小地图开启,每帧 glTexImage2D 重分配地图纹理(约 0.75MB/帧)可单独解释该增速。当前生产包里 MiniMap 模块仍被临时注释,默认不走该路径,但代码路径仍需修好。

改动

  1. 小地图(致命,开启时)
    Minimap.bindTextureBuffer:尺寸变化时才 glTexImage2D,平时改用 glTexSubImage2D

  2. EventDispatcher
    按 listener 身份注销;同 listener+method 去重;ClientSettings 避免配置加载双重注册。

  3. Performance / ItemModelLists
    关闭 CacheItemModels 或禁用模块时 invalidate();总会话 display list 上限 512;禁用时 EntityCulling.reset()

  4. MusicTextures
    有界 LRU + deleteTexture

  5. 其它
    MotionBlur 禁用时删除静态 FBO;DamageIndicator / TargetDisplay 断线与禁用清理;TextRenderer.obfuscatedCache / Utility.messages 有界。

验证

  • ./gradlew test(含 EventDispatcherTest
  • ./gradlew build
  • 小地图:逻辑已修;模块仍默认未注册(与 main 一致)。本地验证可临时 modules.add(new MiniMap())

说明

默认关闭小地图时,十几 GB 仍需结合 MotionBlur New / OptiFine / 原版区块(F3+A)做堆 vs 进程分流。

Open in Web Open in Cursor 

cursoragent and others added 2 commits August 12, 2026 08:21
Bound or free GL/heap resources that could grow for a whole session:
EventDispatcher identity unregister + dedupe, ItemModelLists/EntityCulling
cleanup on Performance disable, MotionBlur FBO delete, MusicTextures LRU
with deleteTexture, and clear static entity refs on disconnect.

Co-authored-by: Gao Yu <gaoyu06@users.noreply.github.com>
bindTextureBuffer used glTexImage2D on every HUD frame (~0.75MB at
512² RGB). That orphans GPU pages at multi-GB/min when MiniMap is on.
Allocate storage once (or on size change) and update with glTexSubImage2D.

Co-authored-by: Gao Yu <gaoyu06@users.noreply.github.com>
@cursor

cursor Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@cursor

cursor Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@gaoyu06
gaoyu06 merged commit 1495016 into main Aug 12, 2026
1 check passed
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.

2 participants