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

Release #1892

Merged
merged 2 commits into from
Jan 17, 2025
Merged

Release #1892

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wise-birds-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@antv/g-lite': patch
---

fix: memory leak caused by function cache
Binary file modified __tests__/integration/snapshots/2d/canvas/text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/2d/svg/gradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/2d/svg/html.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/2d/svg/pattern.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/2d/svg/text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/2d/svg/transformText.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/2d/svg/zIndex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/2d/webgl/html.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/2d/webgl/text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/2d/webgl/transformText.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/2d/webgl/zIndex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/g-lite/src/Canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
isBrowser,
isInFragment,
raf,
memoize,
} from './utils';

export function isCanvas(value: any): value is Canvas {
Expand Down Expand Up @@ -352,6 +353,8 @@ export class Canvas extends EventTarget implements ICanvas {
* @param skipTriggerEvent - whether to skip trigger destroy event
*/
destroy(cleanUp = true, skipTriggerEvent?: boolean) {
memoize.clearCache();

Choose a reason for hiding this comment

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

Ensure that memoize.clearCache() is called appropriately to prevent any unintended cache clearing that might affect other parts of the application.


if (!skipTriggerEvent) {
this.dispatchEvent(new CustomEvent(CanvasEvent.BEFORE_DESTROY));
}
Expand Down
7 changes: 7 additions & 0 deletions packages/g-lite/src/utils/memoize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ export function memoize<F = (...args: unknown[]) => unknown>(
return result;
};
memoized.cache = new (memoize.Cache || Map)();
memoize.cacheList.push(memoized.cache);

return memoized as F;
}

memoize.Cache = Map;
memoize.cacheList = [];
memoize.clearCache = () => {
memoize.cacheList.forEach((cache) =>
(cache as unknown as Map<unknown, unknown>).clear(),
);
};
Loading