* 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.
()
| 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); |
nothing calls this directly
no test coverage detected