Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Supported Pattern or Memory Leak?

$
0
0
Is the following a supported pattern or will it result in a memory leak?

In a can.Control I create a can.compute on a some model attributes:
  1. var self = this;
    MyModel.findOne({id: "0"}).then(function(model) {
    self.options.progress = can.compute(function() {
    return (model.attr('todo') / (model.attr('completed') + model.attr('todo'))) * 100;
    });

            // Rebind event handlers
            self.on();
    });
Then I use templated event binding in the control to have the control bind to changes in the compute like this:
  1. '{progress} change': function(compute, ev, newVal, oldVal) {
    $("#progress_bar").progressbar('value', newVal);
    },

When any of the model attributes in the compute change, the templated event is fired and the progress bar is updated. I thought this was a really cool use of computes and I chose this method cause I figured it would all get cleaned up automatically when the control is destroyed. But...

From what I am seeing, I don't think this all gets cleaned up when the control is destroyed. 

Thoughts?

Viewing all articles
Browse latest Browse all 3491

Trending Articles