Avoiding memory leaks

  • Release all references and destroy all allocated resources (like JQuery widgets) in the destroy event method of the view or view model class
  • Use the view and view model's subscribe method to securely subscribe to Knockout observables. This way the subscription is automatically disposed when the view is destroyed (handled by the framework).

define (["exports"], function (exports) {
	function SampleViewModel() { };

	SampleViewModel.prototype.initialize = function() {		
		var self = this; 
		self.firstName = ko.observable();
		self.subscribe(self.firstName, function() { /* TODO */ } );

	exports.SampleViewModel = SampleViewModel;

Last edited Aug 30, 2013 at 7:35 PM by rsuter, version 7


No comments yet.