Friday, May 30, 2008

Client side Memory Leaks IE and GWT - Introduction

I believe that software development should be fun. This is why for a long time I avoided the wild world of client side and JavaScript. Even though there is a big traction toward AJAX and WEB2.0 I am still not convinced that a group of average developers can develop a large scale, maintainable, enterprise ready and long lasting project based on this technology. JavaScript in just not that kind of language and the freakishly incompatible Browsers world which do not supply comprehensive set of monitoring tools is absolutely a nightmare. Moreover this world is ruled by IE, the two headed beast, which encompasses two GC mechanisms each one of them is not aware to the other. It is so easy to introduce new memory leaks and it is so hard to eliminate them.

I am currently involved in a project written in GWT. I must admit that on the first look this ambitious technology looks quite promising. Developing in Java is much better than JavaScript, GWT offers mitigation to browser incompatibility and IE memory leaks.

Indeed, development phase was quite productive developers did enjoy to develop the code and delivered fast results. (Complications came back when JavaScript native code needed to be written in order to supply needed functionality not supported by GWT--> we were back in the JS alley)

When we approached stabilization phase things became nasty. On one hand performance optimizations where required and we could not ignore the fact that the target engine was JavaScript engine. Moreover the biggest nightmare was memory leaks in IE 6/7. Each indirect circular reference between the DOM and the JS engine caused the entire JS to be locked in memory leading to megabytes of leak. The effort needed to solve memory leaks was huge and involved most of the code written. I will not delve into project constraints and design criteria that might have made this problem so acute. I want to focus on some guidelines to help in avoiding and solving memory leaks. Since this post is getting a bit long I will split those guidelines to the next one.

And one good news to close this post: I opened a bug to Google regarding a memory leak when closing a window 5 months ago. I forgot all about it, buts suddenly out of the blue I got an email. Bug was verified and fixed. Fix will be available for GWT1.5

No comments: