Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I track and debug JavaScript memory leaks in Firefox?

I've been trying to track this one for literally a month now without any success. I have this piece of code on an car advertising website which basically allows thumbnails to rotate in search results given that a car has multiple pictures. You can see it in action at the following:

http://www.abcavendre.com/4506691919/

It is built on the mootools 1.2 framework. The problem is that this script, under Firefox 3, consumes a rather large amount of memory overtime when a page is full of those rotating pictures, such as this inventory page:

http://www.abcavendre.com/Vitrine/Israel_Huttman/

You can see the source of the script in question here:

http://www.abcavendre.com/scripts/showcase_small.js

Any ideas as to what is causing the memory leak? The weird thing is this code behaves properly under IE7.

like image 874
Andrew Moore Avatar asked Oct 14 '08 11:10

Andrew Moore


People also ask

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 you check if there are memory leaks?

One way to check for memory leak is to press and hold down your Windows key and tap the Pause/Break key to bring up System Properties. Click on the Performance tab and check System Resources for the percentage of free or available RAM.

How do you find memory leak source?

To find a memory leak, you've got to look at the system's RAM usage. This can be accomplished in Windows by using the Resource Monitor. In Windows 11/10/8.1: Press Windows+R to open the Run dialog; enter "resmon" and click OK.


1 Answers

A way to track memory leaks in Firefox is with the Leak Monitor Addon. It shows memory leaks of javascript (including extension-scripts).

Please remind that the plugin will sometimes show leaked objects that will get cleaned up later by the garbage collection. If that is the case the plugin will launch a new window showing you the new status.

like image 53
Joe Scylla Avatar answered Oct 13 '22 02:10

Joe Scylla