Click here to Skip to main content
15,511,981 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
My C# windows Service gradually increase the memory usage in 24 hrs it reaches 350 mb..
Can anybody suggest me the solution to fix that?
Note: I am disposing all the objects once used

What I have tried:

Note: I am disposing all the objects once used
Posted
Updated 30-Jan-22 5:08am
Comments
Gerry Schmitz 30-Jan-22 23:45pm    
I don't know what memory usage "proves" ... you need to confirm that 350 MB is "unusual". What did it start at? I have an app that is at 373 MB and I haven't done anything yet ... and that's normal for this app.

We can't help you: we have no idea what your service is doing, much less how it does it!

The best I can offer is this: Attach profiler to .NET service to collect memory data - Visual Studio (Windows) | Microsoft Docs[^] and start looking at what is increasing. When you know that, you can start looking at your code, but since we have no idea what your code is and couldn't run it if we had it, we can't be any more specific.
 
Share this answer
 
Quote:
Note: I am disposing all the objects once used

The memory usage is the proof that you are wrong.
Quote:
Can anybody suggest me the solution to fix that?

The problem being something wrong in your code, the solution is applying specific correction to your code.

The operation of tracking the reason of problem is debugging, the tool is debugger.
As debugging a windows service imply to stop the service execution in middle, you may need to build a specific app in order to stop your code without stopping an active service.

Any help imply having access to full code of your service and spending a lot of time just to learn what does your service and how it does it.
I fear you have to learn debugging tools.
 
Share this answer
 
You need to check your code thoroughly and optimize it. If you are disposing all the objects but there must be some loop holes. and apply performance tuning. Following are the links to optimize your solution and windows service.
.NET Performance Optimization: Everything You Need To Know – Stackify[^]
How to Monitor Windows Services: Performance, Errors, Usage – Stackify[^]
 
Share this answer
 
Comments
Matt T Heffron 2-Feb-22 18:27pm    
This is not an issue of "optimizing" the code, but of debugging.
They are very different things and should never be confused!
"Optimizing" code that isn't working is, in my 40+ years of experience, ALWAYS the wrong thing to do!

"Classic" advice (but still quite appropriate)
The First Rule of Program Optimization:
Don’t do it.
The Second Rule of Program Optimization (for experts only!):
Don’t do it yet.
— Michael Jackson

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900