fix(mask): dispose 后 requestAnimationFrame 循环未停止导致内存泄漏#418
Merged
gaomeng1900 merged 2 commits intoalibaba:mainfrom Apr 13, 2026
Merged
fix(mask): dispose 后 requestAnimationFrame 循环未停止导致内存泄漏#418gaomeng1900 merged 2 commits intoalibaba:mainfrom
gaomeng1900 merged 2 commits intoalibaba:mainfrom
Conversation
…ry leak The #moveCursorToTarget() method recursively schedules itself via requestAnimationFrame, creating a continuous animation loop for the AI cursor. However, dispose() only removes the DOM wrapper element without stopping this loop, causing: - CPU waste: rAF callback continues executing every frame (~60fps) after the mask is disposed, performing unnecessary calculations on a detached cursor element. - Resource leak: Each SimulatorMask instance creates an unrecoverable animation loop that persists for the lifetime of the page. - Console noise: style assignments to removed DOM nodes may produce browser warnings. Fix: Add a #disposed boolean flag, checked at the top of #moveCursorToTarget() to short-circuit the recursion. Set the flag to true in dispose() before removing DOM elements. Changes: - Add #disposed field (default false) - Guard #moveCursorToTarget() with early return when #disposed - Set #disposed = true in dispose() before cleanup
Collaborator
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
修复 SimulatorMask 组件中
equestAnimationFrame 动画循环在 dispose() 调用后不会停止的资源泄漏问题。
Type
问题描述
#moveCursorToTarget() 方法通过
equestAnimationFrame 递归调用自身,为 AI 光标创建持续的动画循环。但 dispose() 方法仅移除了 DOM 包装元素,没有停止这个动画循环,导致:
修复方案
添加 #disposed 布尔标志位:
Changes
Testing
Requirements / 要求
@gaomeng1900 麻烦 review 一下,感谢!