The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

The windows service memory consumption question.

We have native windows service application written by Visual C ++7.1. Seems it has no heap memory leaks. But its memory consumption permanently grows. We have not tested it more than 1day period yet. In 1 day the addition approximately equals 1 MB.  Could be that a stack memory?
We run this app as stand-alone windows console application and VS 7.1 debugger had not show any memory leaks problem there to us.
Do you know the good way to find out what kind of memory occupied there?
Oleg
Saturday, January 28, 2006
 
 
Are you using multithreading or MFC?
Josh McFarlane Send private email
Saturday, January 28, 2006
 
 
It is ATL service project that runs 1 thread with loop inside.
Oleg
Saturday, January 28, 2006
 
 
Hmm... not really sure in that case.

Internally we had a program that was gaining somewhere on the amount of 4-8kb every time it restarted a thread because it was calling some function (CWnd::FromHandle) in MFC that was generating an MFC map and never destroying it until the program shut down.

You may want to check some of your ATL API calls and see if you can narrow it down to any one thing in particular.

Other than that, I don't know of an easy way to check.
Josh McFarlane Send private email
Saturday, January 28, 2006
 
 
Any components? ADO? ADO is known to hoard memory and not release it until the calling process terminates.
MBJ Send private email
Sunday, January 29, 2006
 
 
We use our own FTP component there but 100 % it has no memory leaks. It works for months in .Net windows service apps without restarting now. We suspect that stack grows. I have seen some articles regarding it on www.codeproject.com. Any suggestions?
Oleg
Sunday, January 29, 2006
 
 
Read this.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/thread_stack_size.asp

Perhaps you have one thread killing another, thus the killed thread's stack is not released. It doesn't have to be your code doing it, it could be happening in a system component.
MBJ Send private email
Sunday, January 29, 2006
 
 
Yes, system component, third-party library, also things like SysAllocString that memory leak tools may not catch. There's not an easy answer to memory leaks, I think you just have to be aware of every technique your code uses for dynamic memory allocation so you can search it quickly and visually confirm each allocation has a corresponding deletion. For us we just use new and SysAllocString so when we get a leak we search on those and verify each by hand.
Stan
Sunday, January 29, 2006
 
 
Also see the Memory Management Rules section at this link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncomg/html/msdn_therules.asp

It's related to what Stan was saying. You may not be breaking the rules youself, but some component you are using might.

This is a real problem with servers. If you write a server, you are always at risk if you use anything other than language + WIN32 API.
MBJ Send private email
Monday, January 30, 2006
 
 
Well thanks for an advice regarding COM – I have checked it once again by DebugInterface macro and it is working OK there. All COM rules are at place.
Regarding stack – good article but not our case either.  If a thread was killed by another thread and forgot free whole reserved 1 MB we would have huge leaks there. Probably 100 MB or something likes this.
What do you think regarding this link?
http://www.codeproject.com/cpp/StackShrink.asp
Now we also think get some commercial product like ‘Bounds checker’ to revise the problem from its point of view.
Oleg
Monday, January 30, 2006
 
 
That looks very interesting.

You created one thread in your service, correct? So, in effect, you only have to manage that one thread from the primary service thread?

If so, it looks very doable.
MBJ Send private email
Monday, January 30, 2006
 
 
Yep - correct. The one thread that created on start and stopped on stop with a loop inside:

while (!m_stop)
{
 /// do some useful job here
}

Now we are making some investigations and if you are interested I will post the results in this thread.
Oleg
Monday, January 30, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz