Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

mdVirtualRepeat/mdAutocomplete - browser window resizing causes watchers leak #8178

@noter

Description

@noter

If VirtualRepeat doesn't know item size (like in untouched autocomplete), any window resizing causes new watchers registration:

VirtualRepeatController.prototype.containerUpdated = function() {
  // If itemSize is unknown, attempt to measure it.
  if (!this.itemSize) {
    this.unwatchItemSize_ = this.$scope.$watchCollection(
        this.repeatListExpression,
        angular.bind(this, function(items) {
          if (items && items.length) {
            this.$$rAF(angular.bind(this, this.readItemSize_));
          }
        }));
    if (!this.$rootScope.$$phase) this.$scope.$digest();

    return;

...

Material version: 1.0.7, 1.1.0.RC4
Reproduce: go to https://material.angularjs.org/latest/demo/autocomplete don't focus autocomplete input and resize window
Fix: unbind already registered watcher

VirtualRepeatController.prototype.containerUpdated = function() {
  // If itemSize is unknown, attempt to measure it.
  if (!this.itemSize) {
    if(this.unwatchItemSize_){
      this.unwatchItemSize_();
    }
    this.unwatchItemSize_ = this.$scope.$watchCollection(
        this.repeatListExpression,
        angular.bind(this, function(items) {
          if (items && items.length) {
            this.$$rAF(angular.bind(this, this.readItemSize_));
          }
        }));
    if (!this.$rootScope.$$phase) this.$scope.$digest();

    return;

...

Metadata

Metadata

Assignees

Labels

P4: minorMinor issues. May not be fixed without community contributions.severity: memory leakIssues where a memory leak is triggered.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions