Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check and test how much memory a javascript app is leaking [closed]

iam looking for some tools or ways to detect memory leaks, slow methods in my javascript app.

like image 356
Praveen Prasad Avatar asked Jan 13 '11 21:01

Praveen Prasad


People also ask

How do I know if my application is leaking memory?

The best approach to checking for the existence of a memory leak in your application is by looking at your RAM usage and investigating the total amount of memory been used versus the total amount available. Evidently, it is advisable to obtain snapshots of your memory's heap dump while in a production environment.

Are there 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.

How do I find a memory leak on a Web application?

Start with metrics such as page load times, HTTP request times, and Core Web Vitals – time to the first byte, first contentful paint. If you use Sematext Experience you'll see a number of other useful metrics for your web applications and websites there. However, metrics themselves are only a part of the whole picture.


2 Answers

You need to use the profiler; I recommend Chrome's. In the profiler the steps are

  1. Go to the profile part of the developer tools
  2. Get to the part where the slow js is
  3. Start recording
  4. Start the suspect code
  5. Stop recording

After that, the profiler will tell you everything you want to know about how many objects there are, how much time is spent in each method, etc...

The procedure should be similar with Firebug on Firefox.

like image 154
hvgotcodes Avatar answered Oct 12 '22 23:10

hvgotcodes


Good question. Profilers/browser plugins are handy, but very well may yield results unique to the browser being tested on. There are a number of techniques available from testing via multiple browser's plugins/profilers to inline debugging performance statements.

Two good articles with, robust examples and recommendations:

  1. How do you performance test JavaScript code?
  2. Memory leak patterns in JavaScript
like image 21
xelco52 Avatar answered Oct 13 '22 00:10

xelco52