Comment #3 on issue 2028 by [email protected]: garbage collection issue
http://code.google.com/p/v8/issues/detail?id=2028

// Sample code here, expect this will express the problem clearly
function API() {
    var _history = ["Base Item"],
        _listener = {},
        _handler,
        _self;

    this.find = function (successCB, filter) {
var filterResults = _history; // key place! It will work well if I use utils.copy(_history);
        if (filter) {
            filterResults = filter(filterResults);
        }

        setTimeout(successCB(filterResults), 1);
    };

    this.addListener = function (observerObj) {
        _handler = (new Date()).getTime();

        _listener[_handler] = observerObj;
    };

    this.trigger = function (newItems) {
        var observerObj = _listener[_handler];

        _history.push(newItems);
        observerObj(newItems);
    };
}

function demo(apis) {
    var _historyList;

    function successCB(results) {
        _historyList = results;
    }

    function addedCB(newItems) {
// What should be printed here? [] ? ["Base Item"] ? ["Base Item", "New Item 1"]?
        console.log(_historyList);
        _historyList = _historyList.concat(newItems);
    }
    apis.find(successCB, null);
    apis.addListener(addedCB);

    apis.trigger("New Item 1");
    //apis.trigger(["New Item 2"]);
    //apis.trigger(["New Item 3"]);
}

var apis = new API();
demo(apis);

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to