Share via

Round rectangle and rectangle has memory leaks is this a bug?

Manickam, Suraj 385 Reputation points
2026-03-09T08:49:59.1433333+00:00

I was using https://www.nuget.org/packages/AdamE.MemoryToolkit.Maui/1.0.0 to detect memory leaks in xaml and noticed that stroke shapes round rectangle and rectangle used in border are not getting disposed off when you navigate away from the page ! Is this a know leak or should i raise a github bug?

MAUI Version : 9.0.40

Android Version : 14

Developer technologies | XAML
Developer technologies | XAML

A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.


Answer accepted by question author
  1. Nancy Vo (WICLOUD CORPORATION) 2,805 Reputation points Microsoft External Staff Moderator
    2026-03-09T11:04:44.3133333+00:00

    Hi @Manickam, Suraj ,

    Thanks for reaching out.

    Based on issue, this behavior was reported as a bug in MAUI 8.

    While this is a non-Microsoft link, it’s a GitHub issue and is safe to visit.

    Since there isn’t a clear confirmation in the thread about the status in MAUI 9 or MAUI 10, the safest next step is to verify on the newest MAUI release.

    Hope this helps. If you found my response helpful or informative, I would greatly appreciate it if you could follow this guidance provide feedback. Thank you.


1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-03-09T08:50:15.39+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    This behavior is not listed as a known memory leak for Rectangle or RoundRectangle in .NET MAUI. However, memory leak reports from tools often come from object graphs that are still referenced (and therefore correctly not collected), rather than from a true leak in the framework.

    On Android, circular-reference issues described in the documentation for iOS and Mac Catalyst do not normally occur:

    These circular reference issues are specific to iOS and Mac Catalyst. They do not normally occur on Android or Windows.

    So if the leak is only observed on Android 14 with MAUI 9.0.40, it is more likely related to how the page, bindings, or events are wired than to a platform-wide known bug in the shape types themselves.

    Recommended next steps before opening a GitHub issue:

    1. Verify event subscriptions
      • Ensure that any events involving the page, view models, or long-lived services are unsubscribed when navigating away (for example, in OnDisappearing or Dispose).
      • The MAUI guidance for memory leaks explicitly calls out events as a common cause and recommends using WeakEventManager or unsubscribing when objects are no longer needed.
    2. Use finalizers/logging to confirm collection
      • Add a finalizer to the page or view that hosts the Border/Rectangle/RoundRectangle and log when it is collected:
             ~MyPage()
             {
                 System.Diagnostics.Debug.WriteLine("~" + GetType().Name);
             }
        
      • Navigate to and from the page and confirm whether the page itself is collected. If the page is not collected, the root cause is higher up than the shapes.
    3. Test in a minimal reproduction
      • Create a new MAUI project with a single page containing only a Border with a Rectangle or RoundRectangle stroke and simple navigation between two pages.
      • If the minimal app shows the same behavior (page not collected, shapes retained) with no custom code, that is strong evidence for a framework issue and is appropriate for a GitHub bug.
    4. Consider platform-specific guidance
      • The official guidance on memory leaks in MAUI focuses on:
        • Avoiding strong circular references (especially on iOS/Mac Catalyst).
        • Unsubscribing from events or using WeakEventManager.
        • Using finalizers and profiling to confirm leaks.
      • Apply these patterns in the page that uses the shapes to rule out app-level leaks.

    If, after these checks, a minimal sample still shows that Rectangle/RoundRectangle instances are retained after navigation and the page is otherwise collectible, raising a GitHub issue with that minimal reproduction is appropriate.


    References:

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.