Skip to content

Commit

Permalink
fix(scrollView): resolve memory leaks with holding element references
Browse files Browse the repository at this point in the history
Addresses #1993
  • Loading branch information
ajoslin committed Aug 18, 2014
1 parent ce3f035 commit c5966bb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion js/angular/controller/scrollController.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca

$scope.$on('$destroy', function() {
deregisterInstance();
scrollView.__removeEventHandlers();
scrollView.__cleanup();
ionic.off('resize', resize, $window);
$window.removeEventListener('resize', resize);
backListenDone();
Expand Down
41 changes: 23 additions & 18 deletions js/angular/directive/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,26 +109,31 @@ function($timeout, $controller, $ionicBind) {
} else if(attr.overflowScroll === "true") {
$element.addClass('overflow-scroll');
} else {
var scrollViewOptions = {
el: $element[0],
delegateHandle: attr.delegateHandle,
bouncing: $scope.$eval($scope.hasBouncing),
startX: $scope.$eval($scope.startX) || 0,
startY: $scope.$eval($scope.startY) || 0,
scrollbarX: $scope.$eval($scope.scrollbarX) !== false,
scrollbarY: $scope.$eval($scope.scrollbarY) !== false,
scrollingX: $scope.direction.indexOf('x') >= 0,
scrollingY: $scope.direction.indexOf('y') >= 0,
scrollEventInterval: parseInt($scope.scrollEventInterval, 10) || 10,
scrollingComplete: function() {
$scope.$onScrollComplete({
scrollTop: this.__scrollTop,
scrollLeft: this.__scrollLeft
});
}
};
$controller('$ionicScroll', {
$scope: $scope,
scrollViewOptions: {
el: $element[0],
delegateHandle: attr.delegateHandle,
bouncing: $scope.$eval($scope.hasBouncing),
startX: $scope.$eval($scope.startX) || 0,
startY: $scope.$eval($scope.startY) || 0,
scrollbarX: $scope.$eval($scope.scrollbarX) !== false,
scrollbarY: $scope.$eval($scope.scrollbarY) !== false,
scrollingX: $scope.direction.indexOf('x') >= 0,
scrollingY: $scope.direction.indexOf('y') >= 0,
scrollEventInterval: parseInt($scope.scrollEventInterval, 10) || 10,
scrollingComplete: function() {
$scope.$onScrollComplete({
scrollTop: this.__scrollTop,
scrollLeft: this.__scrollLeft
});
}
}
scrollViewOptions: scrollViewOptions
});

$scope.$on('$destroy', function() {
scrollViewOptions.scrollingComplete = angular.noop;
});
}

Expand Down
1 change: 1 addition & 0 deletions js/angular/directive/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ IonicModule
priority: 1000,
require: ['^?ionNavBar', '^?ionModal'],
compile: function(tElement, tAttrs, transclude) {
if(1) return;
tElement.addClass('pane');
tElement[0].removeAttribute('title');

Expand Down
2 changes: 1 addition & 1 deletion js/angular/service/collectionRepeatManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ function($rootScope, $timeout) {
var rect = self.dimensions[dataIndex];
if (!rect) {

}else if (dataIndex < self.dataSource.dataStartIndex) {
} else if (dataIndex < self.dataSource.dataStartIndex) {
// do nothing
} else {
self.renderItem(dataIndex, rect.primaryPos - self.beforeSize, rect.secondaryPos);
Expand Down
14 changes: 7 additions & 7 deletions js/views/scrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,12 +781,6 @@ ionic.views.Scroll = ionic.views.View.inherit({
}
};

self.options.orgScrollingComplete = self.options.scrollingComplete;
self.options.scrollingComplete = function() {
ionic.tap.removeClonedInputs(container, self);
self.options.orgScrollingComplete();
};

if ('ontouchstart' in window) {
// Touch Events
container.addEventListener("touchstart", self.touchStart, false);
Expand Down Expand Up @@ -869,7 +863,7 @@ ionic.views.Scroll = ionic.views.View.inherit({
}
},

__removeEventHandlers: function() {
__cleanup: function() {
var container = this.__container;

container.removeEventListener('touchstart', self.touchStart);
Expand All @@ -891,6 +885,11 @@ ionic.views.Scroll = ionic.views.View.inherit({
document.removeEventListener("mousemove", self.mouseMove);
document.removeEventListener("mouseup", self.mouseUp);
document.removeEventListener('mousewheel', self.mouseWheel);

delete this.__container;
delete this.__content;
delete this.__indicatorX;
delete this.__indicatorY;
},

/** Create a scroll bar div with the given direction **/
Expand Down Expand Up @@ -1090,6 +1089,7 @@ ionic.views.Scroll = ionic.views.View.inherit({
__scrollingComplete: function() {
var self = this;
self.options.scrollingComplete();
ionic.tap.removeClonedInputs(container, self);

self.__fadeScrollbars('out');
},
Expand Down

0 comments on commit c5966bb

Please sign in to comment.