Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find memory leaks in an app written in react [duplicate]

I have a big application written in ReactJS and wants to find out the memory leaks happening in my code. Is there any tool or technique to find the same?

Regards, SJ

like image 816
Sushil Jain Avatar asked Jun 03 '19 08:06

Sushil Jain


People also ask

How do you check for memory leaks in React app?

const [value, setValue] = useState('checking value...'); useEffect(() => { let isMounted = true; fetchValue(). then(() => { if(isMounted ){ setValue("done!"); // no more error } }); return () => { isMounted = false; }; }, []); In the above code, I've created a boolean variable isMounted , whose initial value is true.

How can you tell if a program has a memory leak?

The simplest way to detect a memory leak is also the way you're most likely to find one: running out of memory. That's also the worst way to discover a leak! Before you run out of memory and crash your application, you're likely to notice your system slowing down.


1 Answers

use google chrome's developers tools Profiling memory performance,
by taking snapshots, Take Heap Snapshot and do Comparison. basically take a snapshot before action, then after action and you can check the "Comparison" view to see if anything was detected.

like image 151
Ashish Kamble Avatar answered Oct 13 '22 22:10

Ashish Kamble