Repository navigation
Memory leak in LayoutInflater.Inflate method when using custom view in XML layout. #11101
Copy link
Copy link
Closed
dotnet/java-interop
#1403Labels
Area: App RuntimeIssues in `libmonodroid.so`.Issues in `libmonodroid.so`.needs-triageIssues that need to be assigned.Issues that need to be assigned.
Description
Activity
- addedArea: App RuntimeIssues in `libmonodroid.so`.Issues in `libmonodroid.so`.needs-triageIssues that need to be assigned.Issues that need to be assigned.
on Apr 9, 2026 maybe related to #10989
How did you "observe" the memory leak?
Was the C#/managed object leaking? or the Java one?
Moved repro in repo with dumps included. These dumps not include reference counter via ConditionalWeakTable. I am comment out ReferenceCounter.AddReferenceAndPrint(this) in CustomView before collect dump data.
Difference between managed dotnet-gcdump show there no active references to custom view

Difference between native am dumpheap shows a native references that not got disposed after GC invoke

If there an active reference counter then you can watch in TextView that count of managed references to CustomView going to increase. I don't know how it's works :(
On net9 there no leaks.
- added 2 commits that reference this issue
on Apr 14, 2026 - added 7 commits that reference this issue
on Apr 14, 2026 - added a commit that references this issue
on Apr 15, 2026 - added 2 commits that reference this issue
on Apr 15, 2026 - added 6 commits that reference this issue
on Apr 16, 2026 - locked and limited conversation to collaborators
on May 17, 2026 - added a commit that references this issue
on Jul 1, 2026
Metadata
Metadata
Assignees
Labels
Area: App RuntimeIssues in `libmonodroid.so`.Issues in `libmonodroid.so`.needs-triageIssues that need to be assigned.Issues that need to be assigned.
Android framework version
net10.0-android
Affected platform version
VS 18.4.11626.88 & 36.1.30/10.0.100
Description
The LayoutInflater.Inflate method can cause a memory leak if the XML layout contains a reference to a custom .net view. A regression has been observed in net10-android. The same code works correctly in net9-android.
Minimal repro in attachment. The example contains a reference counter. You can switch the project from net10-android to net9-android to see the change in behavior.
net10-android-memory-leak-on-inflate.zip
https://github.com/anton-yashin/net10-android-memory-leak-on-inflate
Steps to Reproduce
android-memory-leak.zip
Did you find any workaround?
Nothing.
Relevant log output