Correct Use of the Dispose Method

Problem

Implementation of the dispose method can cause some unobservable errors when using it.

For example, when developing your own component, which has three properties, specified from the outside:

PP.Ui.MyButton = function (settings)

{

    this._ImageList = null;

    this._Metabase = null;

    this._Source = null;

    PP.Ui.Control.call(this, settings);

};

PP.initClass(PP.Ui.MyButton, PP.Ui.Control, "Button");

The example of the created component:

var imgList = new PP.ImageList({ Source: "Icon.png" });

var source = new PP.Exp.EaxAnalyzer();

var mb = new PP.Mb.Metabase();

var btn = new PP.Ui.MyButton({

    ImageList: imgList,

    Source: source,

    Metabase: mb

});

btn.dispose();

After executing the example and executing the dispose method of the button, the dispose method is also called for the source, imgList and mb objects. Because these properties are specified from the outside and two buttons are created, this causes the error. For the properties, which values are the references to the PP.Object objects types and specified from the outside, it is unable to call the dispose method inside the user class of these objects.

Solution

The dispose method must be redetermined in the MyButton class as follows:

PP.Ui.MyButton.prototype.dispose = function ()

{

    delete this._ImageList;

    delete this._Metabase;

    delete this._Source;

    PP.Ui.Control.dispose.apply(this, arguments);

};

NOTE. It is required to call the dispose method of the basic class in the redetermined method.

Since now the dispose method is not called for external objects.

See also:

Web Applications Developers Knowledge Base