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.

setState use call inside of <Animated.Code> memory leak

See original GitHub issue

i try to update my state from animated value, and i subscribe to the animated value and update my state, but it causes memory leak, it updates every 10ms even if the animated value is not changed, i only want the state to be updated when there is a change in the animated value, where i can call from a shouldcomponentUpdate(prevState), but it seems like it can’t retrive the animated value outside of the render. i wonder what is the best way to do this. here is my code: console.log

const {call} = Animated

class SomeComponent extends Component {
constructor(props) {
    super(props);
    this._transY = new Value(0);
    this.state = { height: "", };
  }

 updateHeight = value => {
    requestAnimationFrame(() => {
      this.setState({ newHeight: value });
    });
  };

render(){
   return (
   <Animated.View>
       <Animated.Code>{() => call([this._transY], this.updateHeight)}</Animated.Code>
   </Animated.View>
 )
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
wcandilloncommented, Dec 19, 2019

@osdnk would it make sense to rewrite Animated.Code as a functional component with useCode in order to ensure that the behavior is consistent between the two? If yes, I’d be happy to make a PR.

0reactions
jakub-gonetcommented, Jul 8, 2020

Implemented @wcandillon suggestion in #952.

Read more comments on GitHub >

github_iconTop Results From Across the Web

setState use call inside of <Animated.Code> memory leak #332
i try to update my state from animated value, and i subscribe to the animated value and update my state, but it causes...
Read more >
Memory leak when using setState to overwrite value flutter
This error can occur when code calls setState() from a timer or an animation callback. E/flutter ( 6791): The preferred solution is to ......
Read more >
Solving Memory Leaks with React Native - Enquero
In essence, memory leaks can be defined as memory that is not required by an application anymore that for some reason is not...
Read more >
Avoid Memory Leak With React SetState On An Unmounted ...
Specifically, calling setState() in an unmounted component means that your app is still holding a reference to the component after the component ......
Read more >
Understanding React's useEffect cleanup function
React's useEffect cleanup function saves applications from unwanted behaviors like memory leaks by cleaning up effects.
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