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

fix(virtualRepeat): Memory leak #8056

Closed
wants to merge 4 commits into from
Closed

Conversation

instacat
Copy link
Contributor

Delete all created elements when the scope is destroyed.

Closes #8055

Delete all created elements when the scope is destroyed.

Closes angular#8055
@instacat
Copy link
Contributor Author

@jelbourn Please take a look.

@@ -501,6 +501,12 @@ function VirtualRepeatController($scope, $element, $attrs, $browser, $document,
this.blocks = {};
/** @type {Array<!VirtualRepeatController.Block>} A pool of presently unused blocks. */
this.pooledBlocks = [];

$scope.$on('$destroy', angular.bind(this, function cleanup() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide a unit test to validate that this works?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely needs a unit test to make ensure that this doesn't regress in the future.

@ThomasBurleson ThomasBurleson added the needs: unit tests This PR needs unit tests to cover the changes being proposed label Apr 15, 2016
@ThomasBurleson ThomasBurleson added this to the 1.1.0 milestone Apr 15, 2016
@ThomasBurleson
Copy link
Contributor

👍

@jelbourn jelbourn added the g3: pr This PR was posted by an internal or external product team. label Apr 15, 2016
angular.forEach(this.blocks, removeBlock);
angular.forEach(this.pooledBlocks, removeBlock);
}));
function removeBlock(block) { block.element.remove(); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

element.remove() unfortunately does not work in IE11. It needs to be

if (element.parentNode) {
  element.parentNode.removeChild(element);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also make removeBlock a method on the controller's prototype.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

element.remove() unfortunately does not work in IE11.

Really? Please note that this is jqLite.remove().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about making cleanup() a method on the controller's prototype?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't realize it was a wrapped element. remove is fine, then.

cleanupBlocks() ? Just cleanup by itself isn't descriptive.

@jelbourn
Copy link
Member

cc @kseamon

neko1235 added 2 commits April 15, 2016 17:39
Move cleanup code to cleanupBlocks().
Add unit tests.

Closes angular#8055
@instacat
Copy link
Contributor Author

Please t

@instacat instacat closed this Apr 16, 2016
@instacat instacat reopened this Apr 16, 2016
@instacat
Copy link
Contributor Author

Please take a look.

block.element.remove();
}

angular.forEach(this.blocks, cleanupBlock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is probably not needed (they should be removed along with the parent element). Doesn't hurt much to leave it in, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kseamon You are correct. Removed.

@kseamon
Copy link
Contributor

kseamon commented Apr 18, 2016

LGTM, overall

@jelbourn
Copy link
Member

LGTM

@ThomasBurleson ThomasBurleson added pr: merge ready This PR is ready for a caretaker to review and removed needs: unit tests This PR needs unit tests to cover the changes being proposed labels Apr 18, 2016
@instacat
Copy link
Contributor Author

Thank you.

Do not clean up used blocks.

Closes angular#8055
@ThomasBurleson
Copy link
Contributor

👍

@instacat instacat deleted the patch-1 branch April 19, 2016 20:22
@instacat
Copy link
Contributor Author

Thank you. \o/

jelbourn pushed a commit that referenced this pull request Apr 28, 2016
Delete all created elements when the scope is destroyed.
Move cleanup code to cleanupBlocks().
Do not clean up used blocks.
Add unit tests.

Closes #8055. Closes #8056.
ThomasBurleson pushed a commit that referenced this pull request May 17, 2016
Delete all created elements when the scope is destroyed.
Move cleanup code to cleanupBlocks().
Do not clean up used blocks.
Add unit tests.

Closes #8055. Closes #8056.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
g3: pr This PR was posted by an internal or external product team. pr: merge ready This PR is ready for a caretaker to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants