C
C#2y 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
JakenVeina2y 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
Daltz333OP2y 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
JakenVeina2y ago
uhm okay
something like a background thread that polls an API for information
what about that? how does that answer the question?
Accord
Accord2y 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
Daltz333OP2y 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
Accord2y 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
Daltz333OP2y ago
Not stale
JakenVeina
JakenVeina2y 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
Daltz333OP2y ago
Yep!
Accord
Accord2y 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