How to use Try Catch Finally to dispose garbage
See original GitHub issueI am having garbage collection issues on my application which is built using Abp 1.5.1. Please is there a way to dispose of garbage using the code below?
try
{
entries = _ventryRepository.GetAll().Where(x => x.CustReference == custRef)
.OrderBy(x => x.Id)
.Skip((page - 1) * pageSize)
.Take(pageSize);
longCount = _ventryRepository.GetAll().Where(x => x.CustReference == custRef).LongCount();
}
catch (Exception e)
{
return new TransactionHistoryResponse
{
CustomerId = custRef,
StatusCode = 1,
Message = message
};
}
});
What exactly can I dispose of here in a finally()
block? I want to dispose of as much possible without breaking the application.
Thank you
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Try/Finally block vs calling dispose?
In this case "writer" will point to trash and // The "finally" section will be executed writer = new StreamWriter(.
Read more >How to execute cleanup code using finally
If an exception is thrown before you can close your connection, using the finally block is better than waiting for garbage collection. See...
Read more >Try catch, finally throw — or Exception Handling 101 for .NET
The only action you should worry about is resource disposal. If it's about language without garbage collection (e.g. C++), deallocation is ...
Read more >How assertive should I be in handling exceptions in objects?
Net's garbage collection and exception handling - I want to bulletproof my code and be efficient with objects, but I am trying to...
Read more >Difference between Finally, Finalize and Dispose in C#
Finalize can only be called by the garbage collector and cannot be by the user. Whereas in Dispose the users must explicitly invoke...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In general, you should not dispose an object while using dependency injection.
What is your framework, AspNet Core? Can’t you upgrade to latest ABP since your version is a bit old to provide support.
Okay @acjh just did opened a new issue: #2732