Skip to content
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

fix: memory leak caused by function cache #1891

Merged
merged 2 commits into from
Jan 17, 2025
Merged

fix: memory leak caused by function cache #1891

merged 2 commits into from
Jan 17, 2025

Conversation

wang1212
Copy link
Member

@wang1212 wang1212 commented Jan 17, 2025

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / Document optimization
  • TypeScript definition update
  • Refactoring
  • Performance improvement
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

💡 Background and solution

In some frequently called function scenarios, such as attribute parsing, a cache strategy is used for tool functions to optimize performance. However, this part of the cache is not released in time when the canvas instance is destroyed, resulting in serious memory leaks.

By clearing the function cache in time when the canvas instance is destroyed, the memory leak problem can be safely fixed.

📝 Changelog

Language Changelog
🇺🇸 English fix: memory leak caused by function cache
🇨🇳 Chinese fix: 函数缓存引起的内存泄露

☑️ Self Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

Copy link

Walkthrough

This pull request addresses a critical memory leak issue caused by function caching in the canvas instance. The solution involves clearing the function cache when the canvas instance is destroyed, ensuring that memory is properly released and preventing leaks.

Changes

File Summary
.changeset/wise-birds-begin.md Added a changeset note for the patch fixing the memory leak caused by function cache.
packages/g-lite/src/Canvas.ts Added a call to memoize.clearCache() in the destroy method to clear the function cache when the canvas instance is destroyed.
packages/g-lite/src/utils/memoize.ts Implemented memoize.cacheList and memoize.clearCache() to manage and clear function caches effectively.

@wang1212 wang1212 requested a review from lzxue January 17, 2025 13:17
@wang1212 wang1212 merged commit 6417631 into release Jan 17, 2025
2 checks passed
@wang1212 wang1212 deleted the fix-memory-leak branch January 17, 2025 14:01
wang1212 added a commit that referenced this pull request Jan 17, 2025
* fix: memory leak caused by function cache (#1891)

* fix: memory leak caused by function cache

* chore: update test snapshot

* Version Packages (#1893)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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