Commit 2781332
authored
Unregister from oldGestureHandler when component unmounts (#3374)
## Description
We might have discovered a memory leak associated with oldGestureHandler registry. Nothing ever gets removed from it. We noticed a lot of hanging GenericTouchable components at runtime associated with this registry.
## Test plan
<details>
<summary>Tested on the following code:</summary>
```jsx
import { useState } from 'react';
import { Button, View } from 'react-native';
import {
GestureHandlerRootView,
PanGestureHandler,
} from 'react-native-gesture-handler';
export default function App() {
const [show, setShow] = useState(false);
return (
<GestureHandlerRootView
style={{ flex: 1, alignItems: 'center', justifyContent: 'space-around' }}>
<Button onPress={() => setShow((prev) => !prev)} title="Click me!" />
{show && (
<PanGestureHandler>
<View style={{ width: 100, height: 100, backgroundColor: 'red' }} />
</PanGestureHandler>
)}
</GestureHandlerRootView>
);
}
```
</details>
with
```jsx
setInterval(() => console.log(oldHandlers), 1000);
```
added in `handlersRegistry.tsx`1 parent b696961 commit 2781332
2 files changed
+12
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
| |||
255 | 259 | | |
256 | 260 | | |
257 | 261 | | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
258 | 265 | | |
259 | 266 | | |
260 | 267 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
28 | 32 | | |
29 | 33 | | |
30 | 34 | | |
| |||
0 commit comments