Skip to content

Commit

Permalink
Delete refs to unmounted CellRenderers
Browse files Browse the repository at this point in the history
Summary:
VirtualizedList today will keep refs to cells around, long after they have been unmounted. This leaks memory, and is not needed.

Changelog:
[General][Fixed] - Delete refs to unmounted CellRenderers

Reviewed By: yungsters

Differential Revision: D43835135

fbshipit-source-id: 2104cae977a4e2e9e1a2738e1523ac1796293b4f
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Mar 9, 2023
1 parent 5ac7c7f commit c376e78
Showing 1 changed file with 1 addition and 8 deletions.
9 changes: 1 addition & 8 deletions packages/virtualized-lists/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
}

_onCellUnmount = (cellKey: string) => {
delete this._cellRefs[cellKey];
const curr = this._frames[cellKey];
if (curr) {
this._frames[cellKey] = {...curr, inLayout: false};
Expand Down Expand Up @@ -1879,14 +1880,6 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
const focusedCellIndex = lastFocusedCellRenderer.props.index;
const itemCount = props.getItemCount(props.data);

// The cell may have been unmounted and have a stale index
if (
focusedCellIndex >= itemCount ||
this._indicesToKeys.get(focusedCellIndex) !== this._lastFocusedCellKey
) {
return [];
}

let first = focusedCellIndex;
let heightOfCellsBeforeFocused = 0;
for (
Expand Down

0 comments on commit c376e78

Please sign in to comment.