Skip to content
Merged
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/tender-radios-lose.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/react": patch
---

Fix memory leak by clearing list callbacks when __DestroyLifetime event is triggered.
6 changes: 6 additions & 0 deletions packages/react/runtime/src/snapshot/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export function snapshotCreateList(
componentAtIndexes,
);
const listID = __GetElementUniqueID(list);

lynx.getNative().addEventListener('__DestroyLifetime', () => {
Comment thread
gaoachao marked this conversation as resolved.
Outdated
// Clear the list callbacks to avoid memory leak
__UpdateListCallbacks(list, null, null, null);
});

gSignMap[listID] = signMap;
gRecycleMap[listID] = recycleMap;
return list;
Expand Down
6 changes: 3 additions & 3 deletions packages/react/runtime/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ declare global {
): void;
declare function __UpdateListCallbacks(
list: FiberElement,
componentAtIndex: ComponentAtIndexCallback,
enqueueComponent: EnqueueComponentCallback,
componentAtIndexes: ComponentAtIndexesCallback,
componentAtIndex: ComponentAtIndexCallback | null,
enqueueComponent: EnqueueComponentCallback | null,
componentAtIndexes: ComponentAtIndexesCallback | null,
): void;
declare function __OnLifecycleEvent(...args: any[]): void;
declare function _ReportError(
Expand Down
Loading