-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Memory Leak: MainActivity instances are not garbage-collected after destroy #34879
Copy link
Copy link
Open
Labels
i/regressionThis issue described a confirmed regression on a currently supported versionThis issue described a confirmed regression on a currently supported versionperf/memory-leak 💦Memory usage grows / objects live forever (sub: perf)Memory usage grows / objects live forever (sub: perf)platform/androidregressed-in-10-preview1s/triagedIssue has been reviewedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering TriageVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't workingSomething isn't working
Milestone
Metadata
Metadata
Assignees
Labels
i/regressionThis issue described a confirmed regression on a currently supported versionThis issue described a confirmed regression on a currently supported versionperf/memory-leak 💦Memory usage grows / objects live forever (sub: perf)Memory usage grows / objects live forever (sub: perf)platform/androidregressed-in-10-preview1s/triagedIssue has been reviewedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering TriageVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't workingSomething isn't working
Type
Fields
Give feedbackNo fields configured for issues without a type.
Description
MainActivity instances (and everything referenced from them) never get garbage-collected with MAUI 10.0.51.
Last working version: 9.0.120.
Please have a look at: https://github.com/markusroessler/MauiActivityMemoryleak
This sample app does the following:
Steps to Reproduce
MauiActivityMemoryleak.GCHelper: Information: GC.Collect)in the console you will see something like:
A .NET heap dump showed that there are actually no live MainActivity instances. But in the Java heap dump there are still 3 active instance all referenced by JNI GlobalRefs:

Link to public reproduction project repository
https://github.com/markusroessler/MauiActivityMemoryleak
Version with bug
10.0.50
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
9.0.120 SR12
Affected platforms
Android
Affected platform versions
Android 16
Did you find any workaround?
no, even an explicit
MainActivity.Dispose()doesn't help.Relevant log output