C
C#15mo ago
Daltz333

❔ Do static two way bindings leak XAML?

To summarize, does the following leak the ContentPage here:
<ContentPage>
<Label Text="{Binding Source={x:Static mySingleTon.Instance}, Path=myproperty}"/>
</ContentPage>
<ContentPage>
<Label Text="{Binding Source={x:Static mySingleTon.Instance}, Path=myproperty}"/>
</ContentPage>
If so, would this be an appropriate replacement, or the same issue?
public partial class MyViewModel : ObservableObject {
[ObservableProperty]
public MyObject ObjectA {
get => return mySingleton.Instance.myproperty;
}
}
public partial class MyViewModel : ObservableObject {
[ObservableProperty]
public MyObject ObjectA {
get => return mySingleton.Instance.myproperty;
}
}
Replacement paradigms would be useful.
10 Replies
JakenVeina
JakenVeina15mo ago
what do you mean by "leak the ContentPage"? it seems a LITTLE strange to me to have a static linkage between the View and VM layers like that
Daltz333
Daltz33315mo ago
For example, something like a background thread that polls an API for information, and wanting to continuously consume this API from various parts of the application.
JakenVeina
JakenVeina15mo ago
uhm okay
something like a background thread that polls an API for information
what about that? how does that answer the question?
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Daltz333
Daltz33314mo ago
Not stale, totally forgot to update this. Basically if you have a singleton with an init function, that spawns a thread and updates information contained in itself. The singleton is accessed statically throughout the application. Does this leak pages if the binding is two way?
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Daltz333
Daltz33314mo ago
Not stale
JakenVeina
JakenVeina14mo ago
okay, so you mean a memory leak do pages that bind to this guy get preserved by the binding, even after they've gone out of scope all bindings and subscriptions and such in the View layer are run through WeakReferences, so it should be fine reasonably easy to test for, though
Daltz333
Daltz33314mo ago
Yep!
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts