MCPcopy Index your code
hub / github.com/angular/angular / destroyDetachedRouteHandle

Function destroyDetachedRouteHandle

packages/router/src/route_reuse_strategy.ts:48–59  ·  view source on GitHub ↗
(handle: DetachedRouteHandle)

Source from the content-addressed store, hash-verified

46 * @see [Manually destroying detached route handles](guide/routing/customizing-route-behavior#manually-destroying-detached-route-handles)
47 */
48export function destroyDetachedRouteHandle(handle: DetachedRouteHandle): void {
49 const internalHandle = handle as DetachedRouteHandleInternal;
50 if (internalHandle && internalHandle.componentRef) {
51 internalHandle.componentRef.destroy();
52 // It is critical to destroy the `_localInjector` here. When a route is detached
53 // by the `RouteReuseStrategy`, the `_localInjector` is retained because the
54 // ActivatedRoute object is stored and can be attached later.
55 // When the developer drops the handle (e.g., deciding not to reuse it),
56 // they must manually invoke `destroyDetachedRouteHandle` to prevent a memory leak.
57 internalHandle.route.value._localInjector?.destroy();
58 }
59}
60
61export interface ExperimentalRouteReuseStrategy {
62 shouldDestroyInjector?(route: Route): boolean;

Calls 1

destroyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…