JavaScript and Memory Leaks

I recently finished writing HTML5 Programming with JavaScript For Dummies. This book focuses a lot of attention on working efficiently with JavaScript to produce full-fledged browser-based applications. You’ll find everything from creating simple code to update form entries to creating interesting special effects for your user interface. In fact, I spend considerable time looking at third party libraries such as jQuery and jQuery UI—an incredibly useful set of functions that can significantly reduce coding time.

One of my goals in the book is to introduce you to techniques that produce useful applications in an incredibly short time without writing bad code. The term bad code covers a lot of ground, but one of the more serious issues is one of memory leaks. Applications that have memory leaks will cause the application and everything else on the system to slow down due to a lack of usable memory. In addition, memory leaks can actually cause the application to crash or the system to freeze when all of the available memory is used up. So, it was with great interest that I read an InfoWorld article recently entitled, “Brendan Eich tells how to prevent JavaScript memory leaks.” The article contains a lot of useful advice in writing good JavaScript code that won’t cause your users heartache. Just in case you’ve never heard of him, Brendan Eich is the creator of the JavaScript language, so I’m sure he knows quite a lot about what makes the language tick.

There are a few points of interest in the article. A big one is that the memory leak you’re seeing in your application may not be due to your code—it may be caused by the browser. The potential for browser problems is an important one to keep in mind because these issues affect every application that runs, not just yours. However, when your application performs a lot of work that requires heavy memory use, the user may see your application as the culprit. It pays to track browser issues so that you can support your users properly and recommend browser updates for running your application when appropriate. For that matter, you can simply determine whether the user has one of the poorly designed browsers and tell the user to perform an update instead of running the application.

What I found curious about the article is that it doesn’t discuss other potential sources of memory leaks. For example, using the wrong third party library could cause considerable woe when it comes to memory usage (amongst other issues). Consequently, you need to research any libraries or templates that you use carefully. The libraries, templates, and other tools discussed in my book were chosen with extreme care to ensure you get the best start possible in creating JavaScript applications.

One of the reasons I find JavaScript so compelling as a language is that it has grown to include enough features to create real applications that run in just about any browser on just about any platform. The ability to run applications anywhere at any time has been a long term goal of computer science and it finally seems to be a reality at a certain level. What are your thoughts on JavaScript? Let me know at John@JohnMuellerBooks.com.

 

HTML5/JavaScript Developer Beta Readers Needed

I’m starting a new book project for a book named HTML5 Programming with JavaScript For Dummies. I’ve always been excited about JavaScript because you can use it in so many places. This is the language you want to learn if you want to develop skills that transfer to any device, any operating system, and any environment that supports both HTML5 and JavaScript. This particular book will focus on applications that you typically run within a Web browser, but you can easily use the skills you learn here to perform other tasks with JavaScript.

This is a novice level book at the outset, but quickly moves toward intermediate level tasks. You won’t learn everything there is to know about JavaScript. Rather, you’ll get a great introduction to the language that will help you learn any additional skills you need at an accelerated rate.

I’m assuming that you’ve at least looked at a few Web pages in the past, that you have some idea of what tags are and know the basic tags for a Web page (such as <html>, <head>, and <body>). I’m not assuming very much. You also need to know how to use your computer with some degree of competency. I’m looking for readers of any platform that supports HTML5 and JavaScript. If you want to test my code on a cellphone, please do. I’m specifically targeting the Windows, Mac, and Linux platforms with this book, so I’d love to hear from developers in any of these environments.

It’s important to remember
that beta readers provide direct input on my books while I’m writing
them. In short, you get to help shape the final form of my book. Every
beta reader comment is carefully considered and I implement as many of
your suggestions as possible. Your input is incredibly important at this
phase and unlike many other reader suggestions, you’ll see the results
in the final product, rather than as a post on my blog after the fact.

Don’t
worry about me bugging you for input. You sign up, I send the
manuscript your way, and then, if you choose to provide suggestions on a
particular chapter, you send the suggestions back to me. During the
author review process (when I answer the questions of all of my
editors), I’ll incorporate your suggestions. If you have any desire to
work with HTML5/JavaScript and would like to be a beta reader for this book,
ask for details at John@JohnMuellerBooks.com.