Skip to content

fix: memory overflow by event emitter #3018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025
Merged

fix: memory overflow by event emitter #3018

merged 1 commit into from
Jul 21, 2025

Conversation

lxfu1
Copy link
Member

@lxfu1 lxfu1 commented Jul 21, 2025

Summary by CodeRabbit

  • 新功能
    • 增加了注解相关组件的销毁方法,支持显式清理注解和资源。
  • 优化
    • 增强了 Plot 实例的事件监听和资源管理,系统性跟踪并清理所有事件监听器,防止内存泄漏,确保销毁时彻底释放资源。

Copy link

coderabbitai bot commented Jul 21, 2025

📝 Walkthrough

Walkthrough

本次更改主要为 PlotControllerConversionTag 类引入了更完善的资源清理机制。新增了 destroy() 方法用于销毁注解和监听器,并系统性地跟踪和移除事件监听,确保在销毁实例时不会遗留资源或内存泄漏。

Changes

文件/文件组 变更摘要
packages/plots/src/core/annotation/conversion-tag.ts ConversionTag 类新增 destroy() 公共方法,调用原有 clear()
packages/plots/src/core/annotation/index.ts Controller 类新增 destroy() 公共方法,遍历并销毁所有注解。
packages/plots/src/core/base/index.ts Plot 类引入事件监听跟踪与销毁机制,优化 destroy()render()、事件绑定相关逻辑。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Plot
    participant Chart
    participant AnnotationController
    participant ConversionTag

    User->>Plot: 调用 destroy()
    Plot->>Chart: 移除所有事件监听
    Plot->>AnnotationController: destroy()
    AnnotationController->>ConversionTag: destroy()
    ConversionTag->>ConversionTag: clear()
    Plot->>Chart: destroy()
    Plot->>Plot: 清理引用与标志位
Loading

Estimated code review effort

4 (60–120 分钟)

Poem

小兔挥挥爪,清理不落下,
事件监听全追踪,注解一键刮,
Plot 归于静,内存不再怕,
代码焕新颜,跳跃又萌芽!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/memory-leak

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug 🐛 Something isn't working plots 统计图表G2 labels Jul 21, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/plots/src/core/annotation/index.ts (1)

44-46: 修正 JSDoc 注释中的拼写错误

JSDoc 注释中有拼写错误。

-  /**
-   * Dws the annotations
-   */
+  /**
+   * Destroys the annotations
+   */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22b833e and 2c51a54.

📒 Files selected for processing (3)
  • packages/plots/src/core/annotation/conversion-tag.ts (1 hunks)
  • packages/plots/src/core/annotation/index.ts (1 hunks)
  • packages/plots/src/core/base/index.ts (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: deploy
🔇 Additional comments (7)
packages/plots/src/core/annotation/conversion-tag.ts (1)

153-155: 销毁方法实现正确

新增的 destroy() 方法正确调用了 clear() 来清理注解的内部状态,符合资源清理的最佳实践。

packages/plots/src/core/annotation/index.ts (1)

47-52: 销毁逻辑实现正确

销毁方法正确地遍历所有注解实例并调用它们的 destroy() 方法,最后清空容器映射,有效防止了内存泄漏。

packages/plots/src/core/base/index.ts (5)

25-28: 事件监听器跟踪机制设计合理

新增的 eventListeners 数组和 bindedEvents 标志位为系统化管理事件监听器提供了良好的基础,有助于防止内存泄漏。


75-86: 事件绑定和清理逻辑实现正确

将事件处理函数命名并存储清理函数到 eventListeners 数组中,确保了事件监听器可以被正确移除。


109-112: 渲染时序调整合理

在图表渲染完成后再绑定尺寸传感器事件,确保了事件绑定的正确时机。


197-213: 尺寸监听器绑定逻辑完善

通过 bindedEvents 标志位防止重复绑定,并正确存储了清理函数,实现了完善的事件管理机制。


148-166: 整体清理策略设计良好

除了清理顺序的小问题外,destroy 方法的实现非常全面:

  • 系统化地清理所有事件监听器
  • 正确地销毁注解实例
  • 清空所有引用防止内存泄漏
  • 移除容器属性标记

这些改进有效地解决了事件发射器导致的内存溢出问题。

@lxfu1 lxfu1 merged commit 02b92c5 into v2 Jul 21, 2025
9 checks passed
@lxfu1 lxfu1 deleted the fix/memory-leak branch July 21, 2025 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working plots 统计图表G2 size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: 频繁更新大量数据内存一直膨胀
1 participant