Memory Leak in React-Native

Mehmet Ali Yılgın
2 min readFeb 7, 2022

In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in a way that memory which is no longer needed is not released. A memory leak may also happen when an object is stored in memory but cannot be accessed by the running code.(1)

react-native

Okey. We learned what’s memory leak. If you encounter this error in react-native. U will get this warn: “Warning: Can’t perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.”

I lost four three for solve this problem on my application project. I was getting memory leak error on the following page. There are a lot variables on this page.

memory leak page.

How I fix this problem?

get data from db.

First step, u have to get data from database. Create a state for control UI process.

backAction

Second, write this code when u’ re back from this page. Because u will need 0.2 second for clean the page. ( OR 0.1 second / It doesn’t matter how long the time is. )

useEffect UNMOUNT

Finally, unmount process returns to pop page. ( It will return to the previous page.) Using the “show” variable, design the design in the lower lines depending on this variable.

Congratulations. If you encounter this error and cannot solve it, you can contact me. ( mehmetaliyilgin.com )

--

--