MCPcopy Create free account
hub / github.com/angular/angular / destroy

Method destroy

packages/core/src/di/r3_injector.ts:273–298  ·  view source on GitHub ↗

* Destroy the injector and release references to every instance or provider associated with it. * * Also calls the `OnDestroy` lifecycle hooks of every instance that was created for which a * hook was found.

()

Source from the content-addressed store, hash-verified

271 * hook was found.
272 */
273 override destroy(): void {
274 assertNotDestroyed(this);
275
276 // Set destroyed = true first, in case lifecycle hooks re-enter destroy().
277 this._destroyed = true;
278 const prevConsumer = setActiveConsumer(null);
279 try {
280 // Call all the lifecycle hooks.
281 for (const service of this._ngOnDestroyHooks) {
282 service.ngOnDestroy();
283 }
284 const onDestroyHooks = this._onDestroyHooks;
285 // Reset the _onDestroyHooks array before iterating over it to prevent hooks that unregister
286 // themselves from mutating the array during iteration.
287 this._onDestroyHooks = [];
288 for (const hook of onDestroyHooks) {
289 hook();
290 }
291 } finally {
292 // Release all references.
293 this.records.clear();
294 this._ngOnDestroyHooks.clear();
295 this.injectorDefTypes.clear();
296 setActiveConsumer(prevConsumer);
297 }
298 }
299
300 override onDestroy(callback: () => void): () => void {
301 assertNotDestroyed(this);

Callers

nothing calls this directly

Calls 4

setActiveConsumerFunction · 0.90
assertNotDestroyedFunction · 0.85
ngOnDestroyMethod · 0.65
clearMethod · 0.45

Tested by

no test coverage detected