Subscribe / Unsubscribe Enewsletters | Login | Register

Pencil Banner

Brendan Eich tells how to prevent JavaScript memory leaks

Paul Krill | Jan. 18, 2013
The JavaScript founder details where developers can go wrong and the straightforward methods to stay on track.

InfoWorld: Once leaks occur, what can be done to fix them?

Eich: Leaks require prevention in general, not reactive repair on a running system. If a developer's JavaScript code somehow misses a leak, it is not possible to automatically fix it [on the user's system after the fact]. If a developer did have a big table that carelessly stored references to all objects ever created, of course, you might treat it as a cache and purge old object references from it, but that's not really a leak, just a cache that needs careful tuning and reclamation policy implemented by your JavaScript.

Memory tools can also help. A memory profiler can show which objects are taking up the most memory. Then, a garbage-collection tracing tool can tell which program values are causing those objects to be kept.

 

Previous Page  1  2 

Sign up for CIO Asia eNewsletters.