Browser Memory Leak Test

In an effort to further reduce code size, it was discovered that modern browsers usually remove event listeners from elements that are removed from the page, even if that event listener contains a circular reference to the element. The garbage collector should be able to handle this. This was not always the case.

To check various browsers, a test was made would use more and more memory if the browser had this memory leak. Several major browsers were tested, and these are the results.

Test Results

Google Chrome (50.0.2661.94) No Memory Leak
Mozilla Firefox (45.0.2) No Memory Leak
Opera (36.0.2130.65) No Memory Leak
Apple Safari (9.1, 11601.5.17.1) No Memory Leak
Microsoft Edge No Memory Leak
Internet Explorer 11 No Memory Leak
Internet Explorer 10 Memory Leak
Internet Explorer 9 Memory Leak Possible solution is ineffective
Internet Explorer 8 No Memory Leak Compatibility View has no effect
Internet Explorer 7 Memory Leak
Internet Explorer 6 Memory Leak

Conclusion

While some newer browsers are not susceptible, memory leaks remain a relatively common problem. Therefore, onfontready will be keeping the event listener removal code for the foreseeable future.


Test

We create a series of very memory-heavy iframe onload event listeners on iframes that reference their own element, creating a circular dependency. Once the onload function is called, we immediately remove the iframe. Modern browsers should recognize that the circular depencency has no external references and then remove both. Older versions of IE were known to be unable to detect this correctly.

Run the test while watching the page's memory usage. If the browser is working correctly, the page should consume no more than an additional 2,000 kb after completing the tests. If the browser has a memory leak, it should consume around 16,000 kb after completing the tests.