Skip to content

Commit

Permalink
Fix memory leak in ScrollViewStickyHeader
Browse files Browse the repository at this point in the history
Summary:
Changelog: [internal]

`addListener` call needs a matching `removeListener` call. Otherwise a memory leak is introduced to the app.
This memory leak can retain a UIImage on iOS in Fabric and cause OOM.

Reviewed By: JoshuaGross

Differential Revision: D24860489

fbshipit-source-id: 2625e4bfec416d59e048d9b5ada3813019dd107c
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Nov 11, 2020
1 parent 46be292 commit 3a0927c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Libraries/Components/ScrollView/ScrollViewStickyHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ class ScrollViewStickyHeader extends React.Component<Props, State> {
this.setState({nextHeaderLayoutY: y});
}

componentWillUnmount() {
if (this._translateY != null && this._animatedValueListenerId != null) {
this._translateY.removeListener(this._animatedValueListenerId);
}
if (this._timer) {
clearTimeout(this._timer);
}
}

UNSAFE_componentWillReceiveProps(nextProps: Props) {
if (
nextProps.scrollViewHeight !== this.props.scrollViewHeight ||
Expand Down

0 comments on commit 3a0927c

Please sign in to comment.