iam looking for some tools or ways to detect memory leaks, slow methods in my javascript app.
Asked
Active
Viewed 8,792 times
11
-
Are memory leaks even possible in javascript? – Sam Dufel Jan 13 '11 at 21:35
-
1@Sam `var i=""; while (1) { i+= "Are memory leaks even possible in javascript?";}` - not traditional memory leaks per se... – Byron Whitlock Jan 13 '11 at 21:37
-
1@sam absolutely. bad use of closures can create memory leaks. JS uses a mark and sweep GC, so keeping references to objects that should go away will cause a memory leak – hvgotcodes Jan 13 '11 at 21:53
2 Answers
9
You need to use the profiler; I recommend Chrome's. In the profiler the steps are
- Go to the profile part of the developer tools
- Get to the part where the slow js is
- Start recording
- Start the suspect code
- 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.

hvgotcodes
- 118,147
- 33
- 203
- 236
-
Is there any way to tell which methods are creating the objects that aren't GC? – AJcodez Nov 26 '13 at 03:19
1
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: