C
C#2mo ago
Elio

Garbage Management wpf

Hi, I'd like to know how to manage process memory in my software. Here is some code that has a constructor with a modalNavigationStore parameter, which is a singleton that I never dispose of. I'd like to know if I need to set _modalNavigationStore = null to ensure proper disposal and garbage collection when i'm done with my service ?
public class Service
{
#region Fields
protected TaskCompletionSource<DialogResult>? _dialogtcs;
protected ModalNavigationStore _modalNavigationStore;

#region Constructors
public Service(ModalNavigationStore modalNavigationStore)
{
_modalNavigationStore = modalNavigationStore;
_parameterNavigationService = navigationService;
}
#endregion
}
public class Service
{
#region Fields
protected TaskCompletionSource<DialogResult>? _dialogtcs;
protected ModalNavigationStore _modalNavigationStore;

#region Constructors
public Service(ModalNavigationStore modalNavigationStore)
{
_modalNavigationStore = modalNavigationStore;
_parameterNavigationService = navigationService;
}
#endregion
}
20 Replies
Keswiik
Keswiik2mo ago
You shouldn't need to. Is this service consumed as a singleton as well?
Elio
ElioOP2mo ago
nop this is a transient
Keswiik
Keswiik2mo ago
Either way, unlikely to make a difference as you stated ModalNavigationStore is a singleton. You'll usually only have to be concerned with memory management when interacting with unmanaged resources (like files, for example).
Elio
ElioOP2mo ago
um ok because I feel like i have a memory leak problem and I'm trying to understand what my problem could be
Keswiik
Keswiik2mo ago
What makes you feel like you have a memory leak problem? And assuming you are using visual studio or rider, you should be able to use either's memory profiler to view memory usage in real time when debugging.
Elio
ElioOP2mo ago
The process memory in the diagnostic tools keeps increasing and sometimes never goes down
Keswiik
Keswiik2mo ago
What IDE are you using?
Elio
ElioOP2mo ago
visual studio 2022
Keswiik
Keswiik2mo ago
Then I'd recommend you take advantage of the snapshot feature it has. Start your WPF app, click around for a minute or so, and take a memory snapshot. Then click around for a few more minutes until your memory usage noticeably increases and take another snapshot. You should be able to view the difference between each one and see exactly what is causing the increase.
Keswiik
Keswiik2mo ago
Elio
ElioOP2mo ago
i'm going to take a look to this article because i got this and i can't understand anything for the moment ahah
No description
Elio
ElioOP2mo ago
do you know if hot reaload could be a problem ? should i turn it off ?
Keswiik
Keswiik2mo ago
That's because you're looking at a single snapshot in this picture. You'd need two snapshots, open the latest one and select the first one in the Compare With Baseline option in the top right. No point in making guesses when you have the tools to give you a proper answer
Elio
ElioOP2mo ago
No description
Elio
ElioOP2mo ago
i'll try my best to understand all of this and come back if i need further help. Thanks
Keswiik
Keswiik2mo ago
:PepoSalute: good luck
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Elio
ElioOP2mo ago
It wasn't the full code, I've reduced the size of the file to make my question easier to understand but ok
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Elio
ElioOP2mo ago
Well I'll remove the regions then, I was using rrgion just to sort the code into private, public method and fields
Want results from more Discord servers?
Add your server