Skip to content

unsubscribe some subscriptions on destroy / first some subscriptions - #1549

Merged
jelbourn merged 4 commits into
angular:masterfrom
fxck:observable-cleanups
Oct 20, 2016
Merged

unsubscribe some subscriptions on destroy / first some subscriptions#1549
jelbourn merged 4 commits into
angular:masterfrom
fxck:observable-cleanups

Conversation

@fxck

@fxckfxck commented Oct 20, 2016

Copy link
Copy Markdown
Contributor

I'm not 100% sure you need to unsubscribe those changes subscriptions, but I don't see it being done automatically anywhere(https://github.com/angular/angular/blob/2.1.0/modules/%40angular/core/src/linker/query_list.ts#L11-L100).

Also I'm not 100% sure that dialog and icon needs that first, but looking at code I think both should have it.

There's also a couple of subscriptions on EventEmitter(in sidenav particularly) which I haven't touched since I supposed those are automatically unsubscribed.

Also I haven't touched the one mentioned in #1534

@jelbourn

// edit
looks like changes is event emitter as well https://github.com/angular/angular/blob/master/modules/%40angular/facade/src/async.ts so I guess either it's not needed to unsubscribed at all, or those event emitter subscriptions in sidenav needs to be unsubscribed as well

@googlebotgooglebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Oct 20, 2016

@jelbournjelbourn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like some unit tests are failing as well.

Comment threadsrc/lib/core/line/line.ts Outdated
QueryList
} from '@angular/core';

import { Subscription } from 'rxjs/Subscription';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove spaces from around imported symbol

Comment threadsrc/lib/core/line/line.ts Outdated

public destroy() {
this._changesSubscription.unsubscribe();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This particular unsubscription isn't necessary because the QueryList will be destroyed at the same time as the component (and the subscription is contained within the component that also contains this LineSetter).

Comment threadsrc/lib/sidenav/sidenav.ts Outdated
ngAfterContentInit() {
// On changes, assert on consistency.
this._sidenavs.changes.subscribe(() => this._validateDrawers());
this._sidenavChangesSubscription = this._sidenavs.changes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This one also shouldn't be necessary because the QueryList is destroyed when the component is destroyed

@fxck

fxck commented Oct 20, 2016

Copy link
Copy Markdown
ContributorAuthor

@fxckfxck changed the title unscubscribe some subscriptions on destroy / first some subscriptionsunsubscribe some subscriptions on destroy / first some subscriptionsOct 20, 2016
@jelbourn

Copy link
Copy Markdown
Contributor

@fxckEventEmitter should also be auto-destroyed when the component is destroyed.

@fxck

fxck commented Oct 20, 2016

Copy link
Copy Markdown
ContributorAuthor

@jelbourn I know this is a rather naive test http://plnkr.co/edit/vDeFQunSeXehUssR1Pzr?p=preview but both ViewChildren and Output / EventEmitter seems to still have observers on them even after the component is destroyed.. But it could be something due to caching, since it still got the same amount of observers after toggling the component back in.

@jelbourn

Copy link
Copy Markdown
Contributor

@fxck they still exist in that case because you're saving references to them; if nothing references the emitter, it will be garbage collected.

@fxck

fxck commented Oct 20, 2016

Copy link
Copy Markdown
ContributorAuthor

Alright then, I have removed everything but those few firsts.

@jelbourn

Copy link
Copy Markdown
Contributor

LGTM

@jelbourn
jelbourn merged commit f9c582a into angular:masterOct 20, 2016
@angular-automatic-lock-bot

Copy link
Copy Markdown

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.

@angular-automatic-lock-botangular-automatic-lock-botBot locked and limited conversation to collaborators Sep 6, 2019
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yesPR author has agreed to Google's Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@fxck@jelbourn@googlebot