Open MAUIoxo opened 8 months ago
I see this kind of thing, but I think it is related to the CollectionView and not ObservableRangeCollection.
Does a simple Add operation with a regular ObservableCollection leak?
Absolutely not, when I just use a simple Add(elementToAdd) here
. In this case, it is working fine!
This scenario was meant as a workaround to #20927, when it fires the DataTrigger
on one of my Entrys
or does not consider the data bound value IsValid
. Therefore, always one of my Entrys
gets the Color that was meant be displayed via DataTrigger
when IsValid == false
.
Underneath, my data model has Min
and Max
values and also call OnPropertyChanged(nameof(IsValid))
in this case. On items that are newly selected Min
and Max
both are 0
.
A workaround was the scenario here, in which I wanted to say that the ObservableRangeCollection
changed "The contents of the collection changed dramatically."
So, do you think it is the SharpNado CollectionView then or underneath the CollectionView
of .NET MAUI anyway?
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.
@symbiogenesis - Regarding your question if this also is the case when using a simple ObservableCollcetion
. The answer is "no" - when just using a simple ObservableCollection
and a simple Add(newItem)
it does not leak and I could not detect rising memore consumption so far.
But, this also would not solve and be a workaround for #20927, which was the intention using AddRange(..., NotifyCollectionChangedAction.Reset)
or ReplaceRange(..., NotifyCollectionChangedAction.Reset)
with option NotifyCollectionChangedAction.Reset
(or any other option like new ObservableRangeCollection()
or .Clear()
).
The root cause here appears to be a bug in the 3rd party Sharpnado CollectionView.
The leak expands due to MAUI's propagating leak issue: https://github.com/dotnet/maui/discussions/21918
Thanks for finding out! By the way, I've read your Blog recently about this subject - really appreciate your expertise and knowledge!
Thanks for finding out! By the way, I've read your Blog recently about this subject - really appreciate your expertise and knowledge!
I've done some work to clear out some other leaks in the Sharpnado CV. Maybe open an issue over there and we can get it looked at.
I’ve already opened an issue back then. It’s linked under the following item:
What do you think about replacing it with a DevExpress CollectionView in terms of Memory Issues and Performance? Have you ever done research on that component?
I haven't tried anything from DevExpress yet.
The TearDownBehavior from my toolkit should be able to compartmentalize this leak to the point where you probably wouldn't notice it.
If you do switch to another collection view, my only advice would be to actively monitor your views and pages for GC during development. As you've seen here, it's just too easy to stumble into small leaks, which then become big ones.
Description
When I use
NotifyCollectionChangedAction.Reset
in any kind ofObservableRangeCollection
scenario my released App on iPhone crashes after a while without any error message and no catched-Exception in my App. App is just gone/closed.In the example project below, you can see rising Memory consumption but only when using something like
new ObservableRangeCollection()
,SelectedStoreItems.RemoveRange(toBeDeleted, System.Collections.Specialized.NotifyCollectionChangedAction.Reset);
orSelectedStoreItems.AddRange(newlySelected, System.Collections.Specialized.NotifyCollectionChangedAction.Reset);
.I think I have this effect when any kind of
NotifyCollectionChangedAction.Reset
or.Clear()
is used.In the past, when saw somthing like this on other places, I detected a rising number of event
PropertyNotifyChange
subscriptions without unsubscriptions of them. And this number then almost exploded after a while. Here, I useObservableObject
and[ObservableProperty]
and not my own implementation ofINotifyPropertyChanged
, so I can't see it here.What I can see is, whenever I use
new ObservableRangeCollection()
or any method that usesNotifyCollectionChangedAction.Reset
I see the rising memory consumption. When I useSelectedStoreItems.RemoveRange(toBeDeleted)
orSelectedStoreItems.AddRange(newlySelected)
withoutNotifyCollectionChangedAction.Reset
, memory consumption stays the same.Something like this is severe and I detected it at first when my App on my iPhone was just closed reproducibly! Simulator does not close or provide any hints to find the root of all evil. As this concerns
ObservableRangeCollection
and all otherObservableCollections
, I would say this has to be fixed really soon!!Steps to Reproduce
private async Task CollectSelectedStoreItems()
line 334 and see that methodAddRange(...)
is used with optionSelectedStoreItems.AddRange(newlySelected, System.Collections.Specialized.NotifyCollectionChangedAction.Reset);
BottomSheet
BottomSheet
BottomSheet
and unselect one of the itemsBottomSheet
BottomSheet
the memory consumption is risingprivate async Task CollectSelectedStoreItems()
and use methodSelectedStoreItems.AddRange(..);
without parameterNotifyCollectionChangedAction.Reset
and do the same steps as aboveSelectedStoreItems.RemoveRange(toBeDeleted, System.Collections.Specialized.NotifyCollectionChangedAction.Reset);
with this parameterScenario using
SelectedStoreItems.AddRange(newlySelected, System.Collections.Specialized.NotifyCollectionChangedAction.Reset)
:Scenario using
SelectedStoreItems.AddRange(newlySelected)
:Link to public reproduction project repository
MemoryLeakExample_21015
Version with bug
8.0.10-nightly.10215 but also other versions including .net 7 and .net 8
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android
Affected platform versions
iOS 17.2
Did you find any workaround?
No response
Relevant log output
No response