Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unsubscribe some subscriptions on destroy / first some subscriptions #1549

Merged
merged 4 commits into from
Oct 20, 2016

Conversation

fxck
Copy link
Contributor

@fxck fxck commented Oct 20, 2016

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

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

@jelbourn jelbourn left a comment

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.

@@ -6,6 +6,7 @@ import {
QueryList
} from '@angular/core';

import { Subscription } from 'rxjs/Subscription';
Copy link
Member

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

this._setLineClass(this._lines.length);
});
}

public destroy() {
this._changesSubscription.unsubscribe();
}
Copy link
Member

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).

@@ -271,11 +274,16 @@ export class MdSidenavLayout implements AfterContentInit {
/** TODO: internal */
ngAfterContentInit() {
// On changes, assert on consistency.
this._sidenavs.changes.subscribe(() => this._validateDrawers());
this._sidenavChangesSubscription = this._sidenavs.changes
Copy link
Member

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
Copy link
Contributor Author

fxck commented Oct 20, 2016

@fxck fxck changed the title unscubscribe some subscriptions on destroy / first some subscriptions unsubscribe some subscriptions on destroy / first some subscriptions Oct 20, 2016
@jelbourn
Copy link
Member

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

@fxck
Copy link
Contributor Author

fxck commented Oct 20, 2016

@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
Member

@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
Copy link
Contributor Author

fxck commented Oct 20, 2016

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

@jelbourn
Copy link
Member

LGTM

@jelbourn jelbourn merged commit f9c582a into angular:master Oct 20, 2016
@angular-automatic-lock-bot
Copy link

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-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants