Skip to content

@ContentChildren memory leak with ngTemplateOutlet #14919

Closed

Description

@youdz

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

@ContentChildren somehow gets hold of children that are passed in a template and instantiated through [ngTemplateOutlet], and never gets rid of them even if they are destroyed.

Expected behavior

I am not sure what the correct behavior for @ContentChildren here is (should it see the children or not?) but either way it should not keep a reference to destroyed children. This creates potentially a large memory leak.

Minimal reproduction of the problem with instructions

http://plnkr.co/edit/esib13wg0pTmzVEKhNNM?p=preview
Click on the button a few times, you will see that the QueryList keeps growing. On further inspection, you could see that the children in the list are the ones that were destroyed on each previous toggle.

  • Angular version: 2.4.9
  • Browser: all
  • Language: all

Activity

  1. added
    area: core
    on Mar 4, 2017
  2. alexzuza commented on Mar 4, 2017

    @alexzuza
    Contributor

    I think here is the same issue #14835

  3. nikidimi commented on Mar 17, 2017

    @nikidimi

    I have a similar issue when using NgbTabset from ng-bootstrap and ViewChildren.
    The query list just keeps getting bigger and bigger with every tab change.

    Plunker:
    http://plnkr.co/edit/wOCLhhbAlJEraEie2Tl2?p=preview
    Switch between P1/P2 and then click "Log children" and it will log the query list to the console.

  4. adammedford commented on Mar 23, 2017

    @adammedford

    Just wanted to pile on here since this is currently causing some pretty massive performance issues for me. I've managed to reproduce this with both ng-bootstrap components and the ngx-datatable so I suspect this is a pretty common use case that it leaks on. (As opposed to me doing something wonky/hacked together.)

  5. mhevery commented on Mar 29, 2017

    @mhevery
    Contributor

    Dup of #15578 ?

  6. tbosch commented on Apr 10, 2017

    @tbosch
    Contributor

    Yes, this is a duplicate.

  7. angular-automatic-lock-bot commented on Sep 11, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  8. locked and limited conversation to collaborators on Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coretype: bug/fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions