MCPcopy
hub / github.com/angular/angular / destroy

Method destroy

packages/core/src/di/r3_injector.ts:270–295  ·  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

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