C
C#2y ago
Keeda

❔ When does the IDisposable objects gets automatically disposed ?

public bool Method()
{
bool result = false;
using(var disposableClass = new DisposableClass())
{
result = disposableClass.SomeMethod();
//1. return result;
}
return result; //2.
}
public bool Method()
{
bool result = false;
using(var disposableClass = new DisposableClass())
{
result = disposableClass.SomeMethod();
//1. return result;
}
return result; //2.
}
Now my question is in which case the memory will be disposed if I return it inside the using case or outside of the using case or if it does not matters where the result is returned?
5 Replies
Keeda
KeedaOP2y ago
Is there a way to force GC to release the memory? because my app (WPF desktop app) keeps draining ram after some time Is there any resource link which can help me handle that?
Angius
Angius2y ago
You can use the profiler... somehow It should tell you what uses most memory in your code Not sure, because I never used it to be honest
hime
hime2y ago
Get dotmemory from Jetbrains If you have a license
Keeda
KeedaOP2y ago
Thanks all i will look into it
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