I've read this answer which was very detailed but one had thing caught me eyes:
import { MyThingService } from '../my-thing.service';
@Component({
selector: 'my-thing',
templateUrl: './my-thing.component.html'
})
export class MyThingComponent implements OnDestroy, OnInit {
private ngUnsubscribe: Subject = new Subject();
constructor(
private myThingService: MyThingService,
) { }
ngOnInit() {
this.myThingService.getThings()
.takeUntil(this.ngUnsubscribe)
.subscribe(things => console.log(things));
/* if using lettable operators in rxjs ^5.5.0
this.myThingService.getThings()
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe(things => console.log(things));
*/
this.myThingService.getOtherThings()
.takeUntil(this.ngUnsubscribe)
.subscribe(things => console.log(things));
}
ngOnDestroy() {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}
}
A subject is created to handle all signals to complete. But looking at the subject itself in ngOnDestroy : why did they also complete the subject ? Won't he be collected when garbage collect ? I can agree about the idea that it is right to complete it but it is not necessary since gc will look at the component and see that subject is not used and not reference any other object
Question
Am I missing something here? Must we still call complete ?