eddielee394 / react-native-hindsighttrader

Basic stock market watchlist app built with React Native. Disclaimer: this thing is WIP status on an epic level. Checkout develop branch for latest stuff...
4 stars 7 forks source link

setTimeout causing memory leak in stockscreen component #5

Closed eddielee394 closed 5 years ago

eddielee394 commented 5 years ago

When the setTimeout method starts running it doesn't get cleared when the component unmounts, causing a significant memory leak. If an empty array is passed as a dependency to the hook, the timeout only triggers once and then stops. attempted to run a cleanup function so that the timeout is cleared on unmount, but the timerID keeps changing (hence the timer never being cleared). Need to resolve exactly how to handle disabling a timeout when the component unmounts.

eddielee394 commented 5 years ago

The issue turned out to revolve around RN's stack based navigation and the fact that components aren't actually unmounted when navigated from. So adding a cleanup function in the useEffect hook didn't ever trigger.