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

Warning: observer object was not disposed manually with Dispose() and Missing Dispose call on local IDisposable (cs/local-not-disposed) #26871

Open
vikher opened this issue Dec 30, 2024 · 1 comment
Assignees
Labels
area-architecture Issues with code structure, SDK structure, implementation details platform/iOS 🍎 s/triaged Issue has been reviewed t/bug Something isn't working
Milestone

Comments

@vikher
Copy link

vikher commented Dec 30, 2024

Description

Environment:

.NET MAUI Version: 8.0.93

JetBrains Rider Version: 2024.1.4

CommunityToolkit.Mvvm: 8.3.2

CommunityToolkit.Maui: 9.1.0

Description:
While performing local debugging on both an Android device (Pixel 6 Pro running Android 14) and an iOS simulator (iPhone 15 running iOS 18), I observed the following warning in the logs:

2024-12-30 17:02:11.680874-0600 Mobile[61441:1411563] Warning: observer object was not disposed manually with Dispose()

This warning seems to stem from an ObservableCollection that is loaded after performing a pull-to-refresh operation.

Expected Behavior:
No warnings regarding observer objects not being disposed manually should appear in the logs.

Actual Behavior:
The warning is repeatedly logged, indicating potential resource management issues.

Additional Context:

Observed both in local debugging and Azure DevOps Advanced Security Code Scanning.

Appears linked to ObservableCollection updates after pull-to-refresh.

Image

Missing Dispose call on local IDisposable (cs/local-not-disposed)

Additionally, Azure DevOps Advanced Security Code Scanning is flagging similar warnings in the following generated source files:

Image

Steps to Reproduce

Run the application on an Android Pixel 6 Pro or iOS iPhone 15 Simulator.

Perform a pull-to-refresh action on a screen utilizing an ObservableCollection.

Observe logs in JetBrains Rider or Console.

Link to public reproduction project repository

https://github.com/vikher/testmedia/tree/main/testmedia

Version with bug

8.0.93 SR9.3

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

No response

Affected platforms

iOS, Android

Affected platform versions

Device (Android): Pixel 6 Pro (Android 14) Device (iOS Simulator): iPhone 15 (iOS 18)

Did you find any workaround?

No response

Relevant log output

Additionally, Azure DevOps Advanced Security Code Scanning is flagging similar warnings in the following generated source files:

Mobile/obj/Debug/net8.0-android/generated/CommunityToolkit.Maui.SourceGenerators/CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator/ButtonTextColorTo.g.shared.cs:40
Mobile/obj/Debug/net8.0-android/generated/CommunityToolkit.Maui.SourceGenerators/CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator/DatePickerTextColorTo.g.shared.cs:40
Mobile/obj/Debug/net8.0-android/generated/CommunityToolkit.Maui.SourceGenerators/CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator/InputViewTextColorTo.g.shared.cs:40
Mobile/obj/Debug/net8.0-android/generated/CommunityToolkit.Maui.SourceGenerators/CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator/PickerTextColorTo.g.shared.cs:40
Mobile/obj/Debug/net8.0-android/generated/CommunityToolkit.Maui.SourceGenerators/CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator/LabelTextColorTo.g.shared.cs:40
Mobile/obj/Debug/net8.0-android/generated/CommunityToolkit.Maui.SourceGenerators/CommunityToolkit.Maui.SourceGenerators.Generators.TextColorToGenerator/EntryTextColorTo.g.shared.cs:40
@vikher vikher added the t/bug Something isn't working label Dec 30, 2024
@RoiChen001 RoiChen001 added the s/triaged Issue has been reviewed label Dec 31, 2024
@mattleibow
Copy link
Member

I think the "Missing Dispose call on local IDisposable (cs/local-not-disposed)" error is just in the MCT source generators and is unrelated to "Warning: observer object was not disposed manually with Dispose()". It is also very confusing with all the things but probably not the ObservableCollection.

All of the things have Dispose and Observe in the name, but they are somewhat unrelated.

I think the issue for this repo is "Warning: observer object was not disposed manually with Dispose()" as this is the way iOS does things if you want to listen to some "event" or "property change". We may not be correctly disposing something. Or the MCT may not be disposing something.

The issue for the toolkit is "Missing Dispose call on local IDisposable (cs/local-not-disposed)" as they are generating code that creates an IDisposable object, but they never call dispose.

They may all be related, so I will try have a look next week.

@mattleibow mattleibow self-assigned this Jan 4, 2025
@mattleibow mattleibow added this to the Backlog milestone Jan 4, 2025
@mattleibow mattleibow added platform/iOS 🍎 area-architecture Issues with code structure, SDK structure, implementation details labels Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-architecture Issues with code structure, SDK structure, implementation details platform/iOS 🍎 s/triaged Issue has been reviewed t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants