0

I look for ways or solution to process memory overflow. Possibly restart service when memory overflow or when it grows above some value. Make some work before it die.

I know that is not normal situation and all errors leeds memory overflow needs to be corrected, but I need to be shure that after some issue service will recovered.

UPD I have windows service. This server accepts many connections from clients. Clients make some actions that leeds to memory consumption. Not leak, it just eat memory to process clients reqierments. At some moments (peak load) RAM is not enough. This is not big problem. The problem is that after first memory overflow exception service can't process anything. I have logs full of memory overflow exception. It not self restarting, it not processing clients requests, it not exit from this state.

I just want to find a ways to exit from this state of the service, and if it can not restart it. If it possible to predict such state.

The first way is limit clients, but it not garanted that some client eat very much memory.

Is it posible to detect dangerous memory consumption and stop processing new clients, or correctly restart? Is it posible to selfrestart service if memory is over?

gabba
  • 2,815
  • 2
  • 27
  • 48
  • 2
    by service do you mean windows service or web service? Can you put some more details in your question? – Biser C. Feb 20 '13 at 16:11
  • Thanks. I update question. But problem affects any type of process. – gabba Feb 20 '13 at 16:25
  • 2
    Fix your code, don't put a band-aid on it. Use a memory profiler if you have no idea what's eating all this memory. Btw, automatic service restarts is already built into Windows. Recovery tab in the service properties. – Hans Passant Feb 20 '13 at 18:14
  • Thanks Hans, I do use profiler, I know what use all this memory. Off course I have optimize all what reasonable. Service not crashed, so it is't restarted. I have updated question. Maybe some details pull to you an idea of what i should fix and you share it with me. – gabba Feb 20 '13 at 22:20

1 Answers1

1

Memory overflow is really hard to track/deal with. Most likely you have some sort of a memory leak. Creating memory leaks in .NET is still possible. You cannot deal with memory overflow yourself on a programming level, since you're working in managed environment where you have garbage collection working to eliminate the resources that are no longer used. The best thing to do is to prevent memory leaks. If you want to restart a service when its memory consumptions goes high, you need to use some sort of management package like Microsoft SCOM, which is very comprehensive instrumentation for Windows.

Check these threads also Memory Leak in C#

http://crazorsharp.blogspot.com/2009/03/net-memory-leaks-it-is-possible.html

I hope that helps

Community
  • 1
  • 1
Biser C.
  • 553
  • 5
  • 11