Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool to track down JavaScript memory leak

Tags:

I have a web application which has a memory leak somewhere and I am unable to detect it. I already tried the Chrome developer tools which normally works great, but I am unable to track down the lines of code which are responsible. The Chrome tools just give me too much information and I can't relate the objects in memory to my code.

Are there any other tools that might be helpful?

like image 285
Preli Avatar asked Aug 15 '12 12:08

Preli


People also ask

Which tool is used to detect a memory leak?

Using Memory Profilers Memory profilers are tools that can monitor memory usage and help detect memory leaks in an application. Profilers can also help with analyzing how resources are allocated within an application, for example how much memory and CPU time is being used by each method.

Can you have memory leaks in JavaScript?

The JavaScript engine allocates memory when you create objects and variables in your application, and it is smart enough to clear out the memory when you no longer need the objects. Memory leaks are caused due to flaws in your logic, and they make way for poor performance in your application.


1 Answers

update: Lets use Record Heap Allocations profile type.

  1. open devtools profiler
  2. do a warm-up action
  3. start profiler
  4. repeat action a few times
  5. if the action has a leak you will see the same number of groups of blue bars in the overview pane
  6. stop the profiler
  7. select one group of these blue bars in the overview
  8. look into the list of objects

See screencast Javascript Memory Leak detection (Chrome DevTools)

was: You can use the next scenario for fining memory leaks.

  1. open devtools profiler
  2. do an action that makes a leak
  3. take a heap snapshot
  4. repeat steps 2 and 3 tree times
  5. select the latest heap snapshot
  6. change filter "All Object" to "Objects between Snapshot 1 and 2"

After that you will see objects a set of leaked objects. You can select an object and look at the list of retainers in Object's retaining tree

like image 119
loislo Avatar answered Nov 27 '22 04:11

loislo