Document Information

Last modified:
2008/08/28 04:49 by ecker

Memory Managment

Introduction

Generally, qooxdoo’s runtime will take care of most of the issues around object disposal, so you don’t have to be too anxious if you get those ‘missing destruct declaration’ messages from a verbose disposer run.

To destruct existing objects at the end of your application is an important feature in the ever growing area of web applications. Widgets and models are normally handling a few storage fields on each instance. These fields need the dispose process to work without memory leaks.

Normally, JavaScript automatically cleans up. There is a built-in garbage collector in all engines. But these engines are more or less buggy. One problematic issue is that browsers differentiate between DOM and JavaScript and use different garbage collection systems for each (This does not affect all browsers, though). Problems arise when objects create links between the two systems. Another issue are circular references which could not be easily resolved, especially by engines which rely on a reference counter.

To help the buggy engines to collect the memory correctly it is helpful to dereference complex objects from each other, e.g. instances from maps, arrays and other instances. You don’t need to delete primitive types like strings, booleans and numbers.

qooxdoo has solved this issue from the beginning using the included “dispose” methods which could be overridden and extended by each class. qooxdoo 0.7 introduced a new class declaration. This class declaration supports real “destructors” as known from other languages. These destructors are part of the class declaration. The new style makes it easier to write custom destructor/disposer methods because there are many new helper methods and the whole process has been streamlined to a great extend.

Disposing an application

You can dispose any qooxdoo based application by simply calling qx.core.ObjectRegistry.shutdown(). The simplest possibility is to use the command line included in Firebug. Another possibility is to add a HTML link or a button to your application which executes this command.

You can look at the dispose behaviour of your app if you set the disposer into a verbose mode and then invoke it deliberately while your app is running. This will usually render your app unusable, but you will get all those messages hinting you at object properties that might need to be looked after. How-To instructions can be found here. But mind that the disposer output contains only hints, that still need human interpretation.

Example destructor

destruct : function()
{
  this._disposeFields("_data", "_moreData");
  this._disposeObjects("_buttonOk", "_buttonCancel");
  this._disposeArray("_children");
  this._disposeMap("_registry");
}
  • _disposeFields: Supports multiple arguments. Deleting each key name given from the instance. This is the fastest of the three methods. It basically does the same as the nullify used in qooxdoo 0.6.
  • _disposeObjects: Supports multiple arguments. Dispose the objects (qooxdoo objects) under each key and finally delete the key from the instance like _disposeFields.
  • _disposeArray: Disposes the array under the given key, but disposes all entries in this array first. It must contains instances of qx.core.Object only.
  • _disposeMap: Disposes the map under the given key, but disposes all entries in this map first. It must contains instances of qx.core.Object only.

How to test the destructor

The destructor code allows you an in-depth analysis of the destructors and finds fields which may leak etc. The DOM tree gets also queried for back-references to qooxdoo instances. These checks are not enabled by default because of the time they need on each unload of a typical qooxdoo based application.

To enable these checks you need to select a variant and configure a setting.

The variant qx.debug must be on. The setting qx.disposerDebugLevel must be at least at 1. Higher values mean more output. For a general analysis 1 should be enough. You need to add a setting names “qx.disposerDebugLevel” with the value 1 to your config.json.

Log output from these settings should look something like this:

35443 DEBUG: testgui.Report[1004]: Disposing: [object testgui.Report]FireBug.js (line 75)
Missing destruct definition for '_scroller' in qx.ui.table.pane.FocusIndicator[1111]: [object qx.ui.table.pane.Scroller]Log.js (line 557)
Missing destruct definition for '_lastMouseDownCell' in qx.ui.table.pane.Scroller[1083]: [object Object]Log.js (line 557)
036394 DEBUG: testgui.Form[3306]: Disposing: [object testgui.Form]FireBug.js (line 75)
Missing destruct definition for '_dateFormat' in qx.ui.component.DateChooserButton[3579]: [object qx.util.format.DateFormat]Log.js (line 557)
Missing destruct definition for '_dateFormat' in qx.ui.component.DateChooserButton[3666]: [object qx.util.format.DateFormat]Log.js (line 557)

The nice thing here is that the log messages already indicate which dispose method to use: Every “Missing destruct...” line contains a hint to the type of member that is not being disposed properly, in the “[object ...]” part of the line. As a rule of thumb

  • for native Javascript types (Number, String, Object, ...) use _disposeFields
  • for qooxdoo objects (e.g. qx.util.format.DateFormat, testgui.Report, ...) use _disposeObjects
  • for arrays or maps of qooxdoo objects use _disposeArray or _disposeMap.

Information

Last modified:
2008/08/28 04:49 by ecker

Account

Not logged in

 
 

Job Offers

To further improve qooxdoo we are seeking javascript developers. Read more...

Rich Ajax Platform (RAP)

RAP uses qooxdoo, Java and the Eclipse development model to build rich web applications. Read more...

qooxdoo Web Toolkit (QWT)

Similar to GWT this framework allows to create impressive qooxdoo applications just using Java. Read more...

Pustefix

Pustefix is a MVC-based web application framework using Java and XML/XSLT. Read more...

 
SourceForge.net Logo

Bad Behavior has blocked 0 potential spam attempts in the last 7 days.