Skip to content

Apply finalizer-safe dispose pattern to all IAutoSizableCALayer implementations#33820

Closed
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-comment-issues
Closed

Apply finalizer-safe dispose pattern to all IAutoSizableCALayer implementations#33820
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-comment-issues

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 1, 2026

PR #33818 fixed finalizer crashes in MauiCALayer and StaticCAShapeLayer by guarding native calls behind if (disposing). Review comment correctly identified that StaticCALayer and StaticCAGradientLayer have the same issue.

Changes

All four IAutoSizableCALayer implementations now guard Detach() to prevent calling into potentially deallocated native CALayer objects during finalization:

protected override void Dispose(bool disposing)
{
    if (disposing)  // Only touch native objects during explicit disposal
    {
        _autosizeToSuperLayerBehavior.Detach();
    }
    base.Dispose(disposing);
}

Modified:

  • MauiCALayer.cs
  • StaticCAShapeLayer.cs
  • StaticCALayer.cs ← new
  • StaticCAGradientLayer.cs ← new

Existing test MauiCALayerAutosizeToSuperLayerBehavior_DoesNotLeak validates all four classes.

Original prompt

Please review the following comment #33818 (review) from that PR and please create a new PR that addresses the comment


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…ions

Co-authored-by: PureWeen <5375137+PureWeen@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issues raised in PR review comments Apply finalizer-safe dispose pattern to all IAutoSizableCALayer implementations Feb 1, 2026
Copilot AI requested a review from PureWeen February 1, 2026 14:24
@PureWeen PureWeen closed this Feb 2, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants