Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0:] Microsoft.Maui.Controls.Element: Warning: The RealParent on Microsoft.Maui.Controls.VerticalStackLayout has been Garbage Collected. #25538

Closed
W4lm4s opened this issue Oct 26, 2024 · 4 comments
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter layout-stack platform/android 🤖 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed t/bug Something isn't working

Comments

@W4lm4s
Copy link

W4lm4s commented Oct 26, 2024

Description

Good afternoon,

The debug logs requests to log an issue :

[0:] Microsoft.Maui.Controls.Element: Warning: The RealParent on Microsoft.Maui.Controls.VerticalStackLayout has been Garbage Collected. This should never happen. Please log a bug: https://github.com/dotnet/maui

This happens when I use a popup during navigation or any long running task.
The said popup contains a VerticalStackLayout :

<toolkit:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:ns="clr-namespace:GuaranteesTracker"
             xmlns:currentpage="clr-namespace:GuaranteesTracker"
             x:Class="GuaranteesTracker.AppPopupActivity"
             x:DataType="currentpage:AppPopupActivity"
             Size="50,50"
             CanBeDismissedByTappingOutsideOfPopup="False"
             Color="Transparent"
             xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" VerticalOptions="Center" HorizontalOptions="Center" >
    <VerticalStackLayout VerticalOptions="Center" HorizontalOptions="Center"
                         Opacity="1"
                         IsVisible="{Binding Source={Static Shell.Current}, Path=IsLongLoading, Mode=OneWay, FallbackValue=False}">

        <ActivityIndicator VerticalOptions="Start" HorizontalOptions="CenterAndExpand" HeightRequest="50"
                           BackgroundColor="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource OffBlack}}"
                           IsRunning="{Binding Source={Static Shell.Current}, Path=IsLongLoading, Mode=OneWay, FallbackValue=False}"
                           Color="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource PrimaryDarkText}}" />
    </VerticalStackLayout>
</toolkit:Popup>

Steps to Reproduce

Display a popup while another task is running.

When I do navigation or file creation, some loading can take a while, so I use a pop from CommunityToolkit.Maui.Views to display a loader on the screen.

To do so I call the following line inside a setter :

MainThread.InvokeOnMainThreadAsync(async () 
    => await this.ShowPopupAsync(new AppPopupActivity(), CancellationToken.None).ConfigureAwait(false));

This line seems to be the culprit (Fire and Forget on the mainThread, used to open the popup).

Changing the code to properly await the task via a dedicated method at the right place doesn't change anything, the error remains. (instead of inside a setter)

Using the dispatcher.DispatchAsync and awaiting the task (instead of fire and forget) solved the issue, the error is no longer appearing
return Dispatcher.DispatchAsync(() => this.ShowPopupAsync(new AppPopupActivity(), CancellationToken.None).ConfigureAwait(false));

Calling the Dispatcher this way :

    public Task Test(bool x)
    {
        IsLongLoading = x;
        if (IsLongLoading)
            return Dispatcher.DispatchAsync(() => this.ShowPopupAsync(new AppPopupActivity(), CancellationToken.None));
        return Task.CompletedTask;
    }

Using the mainthread static is too :
return MainThread.InvokeOnMainThreadAsync(() => this.ShowPopupAsync(new AppPopupActivity(), CancellationToken.None));
and
return MainThread.InvokeOnMainThreadAsync(() => this.ShowPopupAsync(new AppPopupActivity(), CancellationToken.None).ConfigureAwait(false));
The Test(bool x) method is awaited later in the code.
With await task;

I hope this helps.

Link to public reproduction project repository

No response

Version with bug

8.0.10 SR3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 13

Did you find any workaround?

I'm just report the bug as requested in the logs.

Working and non-working cases described above.

Relevant log output

[MaterialButton] MaterialButton manages its own background to control elevation, shape, color and states. Consider using backgroundTint, shapeAppearance and other attributes where available. A custom background will ignore these attributes and you should consider handling interaction states such as pressed, focused and disabled
[MaterialButton] MaterialButton manages its own background to control elevation, shape, color and states. Consider using backgroundTint, shapeAppearance and other attributes where available. A custom background will ignore these attributes and you should consider handling interaction states such as pressed, focused and disabled
[MaterialButton] MaterialButton manages its own background to control elevation, shape, color and states. Consider using backgroundTint, shapeAppearance and other attributes where available. A custom background will ignore these attributes and you should consider handling interaction states such as pressed, focused and disabled
[MaterialButton] MaterialButton manages its own background to control elevation, shape, color and states. Consider using backgroundTint, shapeAppearance and other attributes where available. A custom background will ignore these attributes and you should consider handling interaction states such as pressed, focused and disabled
[MaterialButton] MaterialButton manages its own background to control elevation, shape, color and states. Consider using backgroundTint, shapeAppearance and other attributes where available. A custom background will ignore these attributes and you should consider handling interaction states such as pressed, focused and disabled
[EGL_emulation] app_time_stats: avg=5.66ms min=1.95ms max=31.90ms count=22
[0:] Microsoft.Maui.Controls.Element: Warning: The RealParent on Microsoft.Maui.Controls.VerticalStackLayout has been Garbage Collected. This should never happen. Please log a bug: https://github.com/dotnet/maui
[0:] Microsoft.Maui.Controls.Element: Warning: The RealParent on Microsoft.Maui.Controls.VerticalStackLayout has been Garbage Collected. This should never happen. Please log a bug: https://github.com/dotnet/maui
[0:] Microsoft.Maui.Controls.Element: Warning: The RealParent on Microsoft.Maui.Controls.VerticalStackLayout has been Garbage Collected. This should never happen. Please log a bug: https://github.com/dotnet/maui
[0:] Microsoft.Maui.Controls.Element: Warning: The RealParent on Microsoft.Maui.Controls.VerticalStackLayout has been Garbage Collected. This should never happen. Please log a bug: https://github.com/dotnet/maui
[Choreographer] Skipped 165 frames! The application may be doing too much work on its main thread.
[CustomViewTarget] Glide treats LayoutParams.WRAP_CONTENT as a request for an image the size of this device's screen dimensions. If you want to load the original image and are ok with the corresponding memory cost and OOMs (depending on the input size), use .override(Target.SIZE_ORIGINAL). Otherwise, use LayoutParams.MATCH_PARENT, set layout_width and layout_height to fixed dimension, or use .override() with fixed dimensions.
[OpenGLRenderer] Davey! duration=3083ms; Flags=0, FrameTimelineVsyncId=71941, IntendedVsync=8201182432416, Vsync=8203932432306, InputEventId=0, HandleInputStart=8203935751100, AnimationStart=8203935788100, PerformTraversalsStart=8203936954100, DrawStart=8204142729500, FrameDeadline=8201215765748, FrameInterval=8203935565000, FrameStartTime=16666666, SyncQueued=8204222847800, SyncStart=8204228963700, IssueDrawCommandsStart=8204229281400, SwapBuffers=8204258320000, FrameCompleted=8204271574700, DequeueBufferDuration=3643100, QueueBufferDuration=423200, GpuCompleted=8204267769400, SwapBuffersCompleted=8204271574700, DisplayPresentTime=8172253824100,
[EGL_emulation] app_time_stats: avg=12.38ms min=1.94ms max=48.32ms count=24
[Parcel] Expecting binder but got null!
[OpenGLRenderer] Davey! duration=3161ms; Flags=1, FrameTimelineVsyncId=71941, IntendedVsync=8201182432416, Vsync=8203932432306, InputEventId=0, HandleInputStart=8203935751100, AnimationStart=8203935788100, PerformTraversalsStart=8203936954100, DrawStart=8204335200900, FrameDeadline=8201199099082, FrameInterval=8203935565000, FrameStartTime=16666666, SyncQueued=8204339350600, SyncStart=8204395919300, IssueDrawCommandsStart=8204396084500, SwapBuffers=8204398097000, FrameCompleted=8204400389800, DequeueBufferDuration=178200, QueueBufferDuration=738400, GpuCompleted=8204399931000, SwapBuffersCompleted=8204400389800, DisplayPresentTime=0,
[aranteesTracker] Explicit concurrent copying GC freed 27430(1099KB) AllocSpace objects, 3(60KB) LOS objects, 49% free, 11MB/23MB, paused 13.117ms,62us total 64.232ms
Thread started: #39
Thread started: #40

@W4lm4s W4lm4s added the t/bug Something isn't working label Oct 26, 2024
@Pastajello
Copy link

It's best to check on newest version since MaUI is already on sr9.2

@jaosnz-rep jaosnz-rep added the s/triaged Issue has been reviewed label Oct 29, 2024
@jfversluis jfversluis changed the title [0:] Microsoft.Maui.Controls.Element: Warning: The RealParent on Microsoft.Maui.Controls.VerticalStackLayout has been Garbage Collected. This should never happen. Please log a bug: https://github.com/dotnet/maui [0:] Microsoft.Maui.Controls.Element: Warning: The RealParent on Microsoft.Maui.Controls.VerticalStackLayout has been Garbage Collected. Oct 29, 2024
@jfversluis jfversluis added the s/needs-repro Attach a solution or code which reproduces the issue label Oct 29, 2024
@jfversluis
Copy link
Member

It would be super helpful if you could move the relevant code into a reproduction project for us to look at! Thanks!

@samhouts samhouts added platform/android 🤖 area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter labels Oct 29, 2024
@W4lm4s
Copy link
Author

W4lm4s commented Oct 30, 2024

Hi,
I couldn't find a way to make a minimal reproduction project.

My tries weren't sucessfull the layout isn't garbage collected even if I call GC.Collect().

Hours spent on the tracking of the bug ;( for nothing, apparently.

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Oct 30, 2024
@PureWeen
Copy link
Member

Duplicate of #23050

@PureWeen PureWeen marked this as a duplicate of #23050 Oct 31, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Dec 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter layout-stack platform/android 🤖 s/needs-attention Issue has more information and needs another look s/triaged Issue has been reviewed t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants