codeRambler Ramblings on code, the web, and technology

Memory leaks and closures in Javascript
Thursday August 02nd 2007, 11:57 am
Filed under: Javascript, Web development

The topic of memory leaks reared it’s ugly head again recently and I tracked down several good articles and tutorials that discuss and explain some of their causes (and how to prevent them) quite well.

One of the main symptoms of memory leaking is performance slowdown in the browser (this affects all browser, some to a greater degree than others). Investigations of this type of problem invariably lead to Javascript closures – a very powerful feature of Javascript that is very easy to abuse.

For those looking for an explaination of what closures (aka. continuation by some) are and how they are so important to Javascript, take a look at this informative article at

There is a working account of one person’s battle with closure related memory leaks titled IE: where’s my memory?. This article links to many good resources, and has a very well thought out explaination as to why closures are so useful in the first place.

Of course there is a formal description at the MSDN Library as well (complete with diagrams, code examples and patterns).

There is a good tutorial on how to avoid Javascript memory leaks at Jack Slocum’s Blog. This specifically mentions problems experienced with the Dojo Toolkit, (along with Prototype) and even WordPress (used to power this blog).

After reading all those articles, no doubt you will be itching to refactor your existing code!

Books: Mortal Engines by Philip Reeve
Wednesday August 01st 2007, 12:00 pm
Filed under: Books

My commute leaves me about an hour or so every day to indulge in a good read… and whilst I enjoy many different kinds of book, I have found “youth” children’s books to be ideal (given the interruptions you inevitably suffer on a train). A colleague recommended some books by Philip Reeve – a new author (for me), and I’ve been reading his “award-winning Mortal Engines quartet”.

I’ve always had difficulty deciding what to call a series of 4 books, and would normally attempt to refer to them as a quadrilogy – but in this case I was saved by the book cover referring to them as a quartet.

These books are set in a distant future on an Earth that has been reduced to ruin by war (the “Sixty Minute War” was the one that caused the most damage). The ground is a wasteland and resources are scarce. Populations roam around on moving cities (named after cities of today – including London, Brighton and Anchorage). These cities follow the principle of Municipal Darwinism where it’s a “city-eat-city” world full of predator cities chasing down smaller cities and suburbs (also on wheels) and “eating” them – dismantling them for their metal and enslaving their captured inhabitants.

The technology used in the books is a little like that of China Melvielle’s “Steam Punk” genre books and Jules Verne styled contraptions. There are air ships (reminiscient of Zepplins) and submarines to go along with flying “Stalker birds” (dead birds that have been reanimated into some kind of cyborg equivalent) and sand boats that sail the wind across the deserts.

This quartet was a great read. Whilst each book nicely leads into the next, each can be read independently (although it would be a little difficult to follow the later books if you hadn’t completed the first book). Unlike many books, the author doesn’t spend ages updating you on “what has already happened” – this is a welcome relief.

I have now bought some more books by Philip Reeve and look forward to reading more of his work. I hope you do too.

Comments Off