mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
fix(core): Explicitly manage TracingSnapshot lifecycle and dispose of it once it's been used. (#58929)
Provide a callback to the TracingService implementation when a Snapshot can be disposed. The underlying tracing implementation may use refcounting and needs to release resources to enable the trace to complete. While change detection uses the snapshot for exactly one callback, after render runs multiple hooks in the sequence so we need a more predictable way to indicate that the snapshot can be finalized.s PR Close #58929
This commit is contained in:
parent
96c90a5012
commit
3b765367f3
4 changed files with 10 additions and 0 deletions
|
|
@ -604,6 +604,7 @@ export class ApplicationRef {
|
|||
// if one exists. Snapshots may be reference counted by the implementation so
|
||||
// we want to ensure that if we request a snapshot that we use it.
|
||||
snapshot.run(TracingAction.CHANGE_DETECTION, this._tick);
|
||||
snapshot.dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,9 @@ export enum TracingAction {
|
|||
/** A single tracing snapshot. */
|
||||
export interface TracingSnapshot {
|
||||
run<T>(action: TracingAction, fn: () => T): T;
|
||||
|
||||
/** Disposes of the tracing snapshot. Must be run exactly once per TracingSnapshot. */
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -39,6 +42,10 @@ export interface TracingService<T extends TracingSnapshot> {
|
|||
* used when additional work is performed that was scheduled in this context.
|
||||
*
|
||||
* @param linkedSnapshot Optional snapshot to use link to the current context.
|
||||
* The caller is no longer responsible for calling dispose on the linkedSnapshot.
|
||||
*
|
||||
* @return The tracing snapshot. The caller is responsible for diposing of the
|
||||
* snapshot.
|
||||
*/
|
||||
snapshot(linkedSnapshot: T | null): T;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,6 +187,7 @@ export class AfterRenderSequence implements AfterRenderRef {
|
|||
// associates the initial run of the hook with the context that created it.
|
||||
// Follow-up runs are independent of that initial context and have different
|
||||
// triggers.
|
||||
this.snapshot?.dispose();
|
||||
this.snapshot = null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ describe('TracingService', () => {
|
|||
actions.push(action);
|
||||
return fn();
|
||||
},
|
||||
dispose() {},
|
||||
};
|
||||
mockTracingService = {
|
||||
snapshot: jasmine.createSpy('snapshot').and.returnValue(fakeSnapshot),
|
||||
|
|
|
|||
Loading…
Reference in a new issue