question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memoryleak when using the Gesture object

See original GitHub issue

Description

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

https://user-images.githubusercontent.com/32526593/162952109-13bfb87d-8204-4d2f-8bb4-b3cdace506ee.MP4

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:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
j-piaseckicommented, Apr 13, 2022

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.

0reactions
alexstanburycommented, Nov 25, 2022

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”,

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found