Memoryleak when using the Gesture object
See original GitHub issueDescription
There seems to be a memory leak when using the Gesture
object with the GestureDetector
, from the react-native-gesture-handler package.
This is happening for all the different GestureObjects
(LongPress, ForceTouch, etc.), and as soon as I attach one or multiple on
listeners (onBegin, onStart, etc.).
Is there any way, I can detach/remove a listener, when the component unmount?
Platforms
- iOS
Screenshots
Steps To Reproduce
Press the “Toggle” button a few time.
Expected behavior
Memory consumption is steady.
Actual behavior
Memory is building up.
Snack or minimal code example
import * as React from "react";
import { Button, View, ScrollView } from "react-native";
import { Gesture, GestureDetector } from "react-native-gesture-handler";
export const Playground = () => {
const [show, setShow] = React.useState(true);
return (
<ScrollView contentContainerStyle={{ paddingTop: 50 }}>
<Button title={"Toggle"} onPress={() => setShow(!show)} />
{show &&
Array(100)
.fill(true)
.map((v, index) => <GestureBox key={index} />)}
</ScrollView>
);
};
function GestureBox() {
const gesture = Gesture.LongPress().onBegin(() => {});
return (
<GestureDetector gesture={gesture}>
<View
style={[
{
padding: 10,
marginHorizontal: 10,
marginTop: 10,
height: 50,
backgroundColor: "skyblue",
},
]}
/>
</GestureDetector>
);
}
Package versions
- expo: 44
- react: 17.0.1
- react-native: 0.64.3
- react-native-gesture-handler: 2.3.2
- react-native-reanimated: 2.3.1
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Memory Management with Gesture Recognizer - Stack Overflow
A lot of my memory leaks are coming from this code that recognizes swipes. What am I doing wrong? The first line is...
Read more >Memory Leaks with TensorFlow.js hand gestures
I loaded your app, everything is fine so far. · I went to the order page and as expected you load the hand...
Read more >Memory leak from CustomGesture and HDFace - MSDN
It seems the major memory leak is coming from two parts, Custom Gesture and HDFace. 1. Custom Gesture. VisualGestureBuilderFrameSource seems ...
Read more >Memory Leaks with SwiftUI | Apple Developer Forums
It works well when only active onTapGestrue or matchedGeometryEffect modifier, but seems to get memory leak when active both modifiers.
Read more >iOS Swift — How to Avoid Memory Leaks - Medium
This weak reference can be used when ever parent is pointing child and child also has parent object. This type of reference looks...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi! It looks like it happens only when Gesture Handler is using Reanimated to handle events, I’ll pass it on to the Reanimated team so they can take a look.
I’m still seeing this issue using 2.6.0, resolved by using runOnJS.
“react-native”: “^0.70.6”, “react-native-reanimated”: “^2.12.0”, “react-native-gesture-handler”: “^2.6.0”,