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.

Possible memory leak

See original GitHub issue

Possible memory leak when animating fontSize using withSpring

Hello, guys! I’m testing different types of animations using reanimated 2 and found a possible memory leak. The conditions are as follows. I have a button that changes local state (bool). There is also an effect that triggers a spring animation on some shared value (from 0 to 1 and vice versa). And the actual problem appears when I add useAnimatedStyle which interpolates shared value to the appropriate fontSize of the Animated.Text. Now if I press the button multiple times, each time I press it the consumed memory increases by about 2MB each time animation starts and never resumes to its initial value.

Description

See above

Expected behavior

There shouldn’t be any leaks

Actual behavior & steps to reproduce

each time I press it the consumed memory increases by about 2MB each time animation starts and never resumes to its initial value

Snack or minimal code example

https://github.com/schusovskoy/reanimated-test

import React, { useEffect, useState } from 'react'
import styled from 'styled-components/native'
import Animated, {
  interpolate,
  useAnimatedStyle,
  useSharedValue,
  withSpring,
} from 'react-native-reanimated'

const Container = styled.View`
  flex: 1;
  padding: 0 16px;
`

const Button = styled.TouchableOpacity`
  position: absolute;
  bottom: 32px;
  height: 64px;
  right: 16px;
  left: 16px;
  background: #fff;
  border-radius: 24px;
  justify-content: center;
  align-items: center;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
`
const ButtonText = styled.Text`
  font-size: 16px;
`

const App = () => {
  const value = useSharedValue(0)
  const [state, setState] = useState(false)

  useEffect(() => {
    value.value = withSpring(state ? 1 : 0)
  }, [state, value])

  const style = useAnimatedStyle(() => {
    return {
      fontSize: interpolate(value.value, [0, 1], [28, 16]),
    }
  })

  return (
    <Container>
      <Animated.Text style={[{ marginTop: 100 }, style]}>
        Some text
      </Animated.Text>
      <Button onPress={() => setState(!state)}>
        <ButtonText>Press me</ButtonText>
      </Button>
    </Container>
  )
}

export default App

Package versions

“react-native”: “0.66.1”, “react-native-gesture-handler”: “^1.10.3”, “react-native-reanimated”: “^2.2.3”,

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
tapzcommented, Jan 29, 2022

Sure. But #2849 should be updated to apply also to iOS.

1reaction
amsimoncommented, May 12, 2022

Still encountering this issue. Reanimated is unusable in its current state.

Read more comments on GitHub >

github_iconTop Results From Across the Web

My system scan results says "An active process has a possible ...
My system scan keeps telling me "An active process has a possible memory leak (Microsoft EdgeCP.exe)
Read more >
How do I check for memory leaks, and what should I do to stop ...
To find a memory leak, you've got to look at the system's RAM usage. This can be accomplished in Windows by using the...
Read more >
Memory leak / Handle leak | Firefox Support Forum
Here is a fairly simple explanation for a memory leak: A Memory leak occurs when your computer closes an open program and that...
Read more >
Memory leak - Wikipedia
In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in...
Read more >
Fix: An Active Process Has a Possible Memory Leak
No more memory leaks with a new user account · If you encounter a possible memory leak, it means that a program is...
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