-2

We have a program written in C#, used as a server. It's a Windows service. This program often uses all the memory of the machine, but I do not know what causes this. What can I do?

my program used as a Official server already,and i can not restart it Casual ,so i can not use any tools ,because tool need restart my program and can not Attach to Process. And i do not know potentially harmful code ,because my program have so many code.

  • Do you have the source code for the application? And if so, did you understand, what it is doing? – Romano Zumbé Jul 01 '13 at 08:30
  • Show your work and tell people what have you tried. – Soner Gönül Jul 01 '13 at 08:30
  • 1
    Sounds like a memory leak... Does it happen at a certain part of the application? You could try profiling it depending on tools you have or on very basic level running Task Manager and watch memory use during certain operations to see if you can see where memory leak appears (i.e. during a certain phase of the service). – Belogix Jul 01 '13 at 08:30
  • Use a memory profiler like .Net Memory Profiler. http://memprofiler.com/ – Azhar Khorasany Jul 01 '13 at 08:31
  • Show us some of the code that you think may be causing this. Or if you don't know which part is causing the memory usage then start chopping pieces out (comment out large parts) and see when the performance improves – WheretheresaWill Jul 01 '13 at 08:31
  • Visual Studio Performance Analyzer (Analyze > Start Performance Analysis) – User 12345678 Jul 01 '13 at 08:32
  • my program used as a Official server already,and i can not restart it Casual ,so i can not use any tools ,because tool need restart my program and can not Attach to Process. And i do not know potentially harmful code ,because my program have so many code. – user2538281 Jul 01 '13 at 09:20
  • "i do not know potentially harmful code ,because my program have so many code." Then it's too late for you. – Daniel Daranas Jul 01 '13 at 09:24

2 Answers2

2

There are dfferent tools which can help you to investigate issues like this.

The most simple is a loging in start of potentially harmful code and in process of that.

If you have no idea, were that code could be, you may look on :

MemoryProfiler from JetBrains

or free one from MS, like :

MS Profiler, but it's not so intuitive to use.

Matthew Watson
  • 104,400
  • 10
  • 158
  • 276
Tigran
  • 61,654
  • 8
  • 86
  • 123
  • yes,I try that already ,but, all tools can not Attach to Process ,must restart the promgram. and I want to writter log but C# can not get the memory use of a thread ! – user2538281 Jul 01 '13 at 09:01
  • @user2538281: are ou sure that JetBrains is not able "connect to process" ? – Tigran Jul 01 '13 at 15:34
  • yes I use it ,it only can used when i start my program with it ,can not Attach to Process, does not it? i used dotTrace Profiler 3.1 – user2538281 Jul 02 '13 at 06:24
  • seems actually you are right, *there is* attach process but for performance and not memory. Can you run your web service like and ordinary application (timer ??) and profile it like that? – Tigran Jul 02 '13 at 06:32
  • i can do that change it to ordinary application,but there is tow Problem。1.i must used it in Official environment,because in our Test Environment we can not Reappear this,we do not know what Operate user did can cause this. 2.if i use it in Official environment ,i am not allowed to use profile tools ,maybe profiler tools will cuase Bad performance – user2538281 Jul 02 '13 at 06:49
  • @user2538281: I'm afraid, at this point, the only choice you have is logging. You can use http://stackoverflow.com/questions/3296211/how-to-get-the-size-of-available-system-memory to check at what moments in icreases, and may be only for debug reasons, you can, in case when you rich the limit, show a message to a user, so they call you, and you look on logs. There is no easy solution – Tigran Jul 02 '13 at 07:01
  • yes,it is a no easy solution,and it is our Last resort,i have think about it. but i think it L ow success rate about that plan,our program have High concurrency,this plan may help us to Refine。 thank you very much – user2538281 Jul 02 '13 at 07:25
  • by the way i know windebug can help this, but it hard to use. – user2538281 Jul 02 '13 at 07:34
  • @user2538281: you can sue remote debuging of VS too, if you are able to connect to remote machine and upload there PDB. But as much as I understood, you are not able to connect to that machine. – Tigran Jul 02 '13 at 07:43
  • if the remote machine as server work well i can not debug it ,but if it down i can use it ,are you sure i can use remote debuging of VS to see something when my server's memory full? how can i do that? – user2538281 Jul 02 '13 at 08:00
  • I don't know if you can or not, cause you need to run remote on that machine that hosts requests from VS. Look here for detailed description of steps for setup: http://msdn.microsoft.com/it-it/library/bt727f1t.aspx – Tigran Jul 02 '13 at 08:02
  • i think it is not useful for me,i want to konw who used the memory ,but remote debug can not help me do this. thank you ! – user2538281 Jul 02 '13 at 08:12
0

I suggest that you use Ants memory profiler. I think it is very easy and intuitive to use though quite powerful tool. It's not free, but it's worth it if you have memory issues.

Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207