Dojo Stateful with hitched observer callback


This example creates an observer to a Stateful with a hitched callback. The handle is removed. The current Stateful implementation keeps a reference to the callback, which will keep a reference to the observer as the callback was hitched.

Verify the behavior

Open this page in Google Chrome. Open Activity monitor (shift + escape) to observe memory usage. Notice that it never drops. Open web inspector. Take a heap snapshot. Click on the heap snapshot. Expand the "(string)" node and you'll find the long string at the top.

You can also verify it for IE and FF if you look at the memory for the process in activity monitor.


// global scoped variable to simulate Stateful that lives longer than the observer 
var globalmodel;

], function(
) {
    // model to observe
    globalmodel = new Stateful();
    // the observer with a 50,000,000 character long string property, 
    // to make it easy to spot in heap profiler
    var observer = {
    	LONGSTRINGPROPERTY: Array(5e7).join("."),
    	modelValueChanged: function() { }
    // observe handle
    var handle ="prop", lang.hitch(observer, observer.modelValueChanged));	

    // remove the handle