Lifetime management: Explicit peer-lifetime state + transition choke point - #11875
Open
Protik Biswas (protikbiswas100) wants to merge 3 commits into
Open
Protik Biswas (protikbiswas100) wants to merge 3 commits into
Protik Biswas (protikbiswas100) wants to merge 3 commits into
Conversation
…hoke point
Add PeerLifetimeState {Detached,Pegged,Tracked,Releasing,TornDown} and a single
TransitionPeerState choke point on the framework peer base
(ctl::WeakReferenceSourceNoThreadId), where the peg/tracker bookkeeping actually
lives.
This is the compat-shim phase of Pillar A: GetPeerLifetimeState() is *derived*
from the existing scattered fields (m_ulPegRefCount, m_bIsPeggedNoRef,
m_bReferenceTrackerPeg, bRefCountPeg, m_ulExpectedRefCount, disconnect flags) so
it can never drift from reality while the rest of the framework still mutates
those fields directly. TransitionPeerState is a non-fatal observability/assertion
gate wired into the real peg primitives (UpdatePeg/PegNoRef/UnpegNoRef) under DBG,
so retail is zero-cost and shipping builds cannot be destabilized.
No behavioral change. Establishes the dependency root for migrating the ~62
peg/unpeg call sites onto the transition API in subsequent changes.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1677a4a7-252f-4dae-82bb-c43c6e88340c
…gh the choke point
Extend the Pillar A observability from PR (1/N) to the remaining lifetime edges
that peg-counting alone doesn't cover:
* ConnectFromTrackerSource / DisconnectFromTrackerSource -> the Tracked<->Detached
edges as a reference-tracker source starts/stops rooting the peer.
* SetRefCountPeg / ClearRefCountPeg -> the implicit GC-walk root applied/removed
during a reference-tracker walk.
Each announces its transition through TransitionPeerState. Still DBG-only and
non-fatal (zero retail cost, no behavior change); builds directly on the derived
GetPeerLifetimeState() introduced in (1/N).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1677a4a7-252f-4dae-82bb-c43c6e88340c
Complete the peer-lifetime state machine's terminal lifecycle, which the
peg/tracker instrumentation in (1/N) and (2/N) does not cover:
* DirectUI::DependencyObject::OnFinalRelease -> announce the peer entering
final release (-> Releasing).
* DirectUI::DependencyObject::DisconnectFrameworkPeerCore -> capture the state
before teardown and announce the terminal transition once the disconnect
flags are set (-> TornDown).
Both route through TransitionPeerState. DBG-only and non-fatal (zero retail cost,
no behavioral change); the release/disconnect paths themselves are untouched.
Together (1/N)+(2/N)+(3/N) give the state machine full observability across the
peg, tracker, and teardown edges, which the later native call-site migrations
will assert against.
Built: wrtdxamlfoundation.lib (Debug|x64) compiles clean with these changes.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1677a4a7-252f-4dae-82bb-c43c6e88340c
Protik Biswas (protikbiswas100)
requested a review
from a team
as a code owner
September 14, 2026 03:31
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
Author
|
/azp run |
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds an explicit peer-lifetime state machine to track the lifetime relationship between a native
DependencyObjectand its managed peer, so the transition between "connected" and "torn down" is observable at a single, well-defined point instead of being implicit.Fixes
https://task.ms/64051050
Why
XAML objects exist as a native/managed pair whose lifetimes must stay in sync. Today the connect/disconnect and teardown transitions are scattered and implicit, which makes premature release and over-hold bugs hard to reason about. This change centralizes those transitions so peer lifetime can be tracked reliably.
Changes
Releasing/TornDowntransitions at the peer teardown funnel.Files touched
dxaml/xcp/dxaml/lifetime/inc/WeakReferenceSourceNoThreadId.h(+36)dxaml/xcp/dxaml/lifetime/lib/WeakReferenceSourceNoThreadId.cpp(+190)dxaml/xcp/dxaml/lib/DependencyObject.cpp(+18)Net: 3 files changed, 244 insertions (additive only, no deletions).