Resource Problem

I have an application that seems to randomly eat up resources. It will be running along fine and then at an instant it will chew up ALL available resources. The problem is also very random and I can't make it happen all of the time. I've debugged it extensively using the Microsoft Visual C++ debugger as well as Numega's Bounds Checker and nothing comes up. My question is : What could cause something like this? and why doesn't it show up in my debuggers? Any help would be appreciated. Thanks.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tommy HuiEngineerCommented:
How are you sure that it is your application? Is this under Win95 or NT?
What sort of resources are your talking about?  How do you know it is running out of these resources?
dougcAuthor Commented:
1 . This problem has occurred when my application was the only one that was running so I'm convinced that it's my application that is the problem (I run multiple instances of my Application at once)

2. I'm running my Application under Windows 95

3. All 3 resources (GDI,USER & SYSTEM) are at 0% free.
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

1.  Lots of things are still running, like the shell and drivers.  But your application probably is the culprit.

2.  What resources are being used up.  Windows?  Menus?  Device contexts?  System Timers?  How do you know what resources are being used up?  What symptoms do you see or what tools to you use?

3.  What does you application do.  How was it written?  What I'm looking for is things that caould be related to this.  Like if you handle WM_PAINT messages.  Do you create system timers.  Do you have a lot of menus?  Do you register lots of classes etc.
dougcAuthor Commented:
1. I'm not sure what resources are being used up. I'm using the Resource Meter that comes with Windows 95. One minute all of the resources (GDI,USER ans SYSTEM) read normal and after the problem occurs they all read 0%. My system locks up and when I use CTRL-ALT-DELETE and I get a white dialog box that says "System is Dangerously low on resources" and then I end up rebooting. Are there any other "Resource Meter" type programs that would be better?

2. My application is written in C Windows. It uses many Menus and System Timers and I register about 24 different Window Classes. I don't use the standard Windows Buttons, Editboxes etc.. I've created my own Buttons, Editbooxes etc.. and therefore handle the WM_PAINT messages for these windows myself.

3. This problem occurs infrequently and I can't reproduce on demand.
I was told by a Microsoft support engineer that the resource meter is useless.  Supposidly it never reads high regardless of the situation.  So I wouldn't put too much faith in it, although it IS reading high for you.

The obvious thing to look for is cases where you don't clean up.  Places where you get a DC and don't release, create a font and don't destroy it etc.

A less obvious thing is to look for recursion.  If you have code that does clean up, but recurses before it cleans up, you can consume a resource by recursing too deep.  Given the description of the behavior, it might be a case where things recurse by mistake, rather than on purpose.

Do you have any handle on when the problem occurs.  For example, can it occur when the system is just sitting idle?  Or is only when the user types, etc.
Hi, Dougc

I think I know what will help U -
go to this site :
and download - MemCheck 5.0.
It's 299$, but U have full 14 day for try.

Here's some commercials:)
just in case - from their site

What does MemCheck do?

Instead of hunting through reams of hex dumps and
pawing through stacks of (someone else's) code, you'll
see a clear picture of what went wrong, and why: function
names, line numbers, stack traces, DLL names, parameters,
parameter snapshots, fully translated "last error" values,
and more.  From the Wizard, you have many options,
including viewing the source for the error, dropping into
your debugger, ignoring the error, or terminating the

How does MemCheck work?

As your application runs, it makes calls to the Windows
API and runtime routines. MemCheck 5.0 transparently
intercepts the most important, most error-prone calls --
about 520 in all -- and looks for API failures, invalid pointers
and handles, stack trashing, heap corruption, and memory
and resource leaks.

... MemCheck examines the portable executable format (PE)
of not only your application, but of all the DLLs that are loaded
in the application's process space. It then simply redirects
calls it's interested in to the MemCheck DLL, where it checks
the function's parameters for "sanity," then hands off to the real
target API routine. When the function returns, the value returned
is examined for failure conditions and any "last error" codes
from GetLastError() are recorded. (MemCheck gives you the
actual text of the error as well as the error number...) No source
code is required for this whole process -- no kidding.

...Without any source code or debugging info, MemCheck
can tell you about overwrites, leaks, and all the other errors.
You'll know exactly what's going on with the target application.
Are you trashing memory by writing too many bytes to a buffer?
Corrupting the heap by freeing a bad heap handle? Trusting
the innards of GDI32 by playing with an invalid HWND
(or CWnd)? Is your application suffering a slow strangulation
from lack of resources? MemCheck will be able to tell you this
and more just five minutes after you install it.

A BoundsChecked application can take many times longer
than usual to run, increasing the penalty for "checking early,
checking often." MemCheck becomes part of your executable
or DLL -- that is, the MemCheck DLL is linked implicitly -- so you
can even debug your application in your favorite IDE while
MemCheck's running! (Try that with BounceChecker or other

Which compilers does MemCheck 5.0 support?
MemCheck supports Visual C++ 4.x and 5.0; Borland C++ 4.5x
and 5.x.

Does MemCheck integrate into my IDE?
It features integration with the Visual C++ Workbench.

Good luck
Regards, Happy1
dougcAuthor Commented:
Thank you Happy1 for your response but I tried MemCheck and nothing came up that didn't come up with Numega's Bounds Checker. I need to know what would cause this problem. Perhaps a source code example of a program that can use ALL the resources at once and at an instant. Our problem is that we don't know what to look for??
Are there any other problems with the program?  This could be caused by a bug that SEEMS harmless that you haven't gotten around to fixing.  I once spent hours trying to track down a bug with no luck.  I gave up and fixed a harmless display glitch that had been bothering me for the longest time and... the other bug was gone.

If that doesn't help.  Can you give us more information about the nature of the program?  How about the occurances of the problem (as I asked above).  Can you dissable portions of your program and cause the problem to go away?  (or not in which case you know the problem isn't in those portions.)

Was there a time when the problem didn't exist?  Do you know what things have changed since then?
dougcAuthor Commented:
Adjusted points to 1000
Try commenting out your entire program, except for the main() function. One by one, start adding features back in, each time running the program start to finish - make the program do everything it possibly can. I've found this method, when coupled with System Monitor, to be extremely tedious but rather effective.

Unless you can send us the program to peruse, there isn't too much more we can do...

(but hey, for 1000 points and a good grade...)
dougcAuthor Commented:
This will not work with this program. The error does not happen very often (about once every 1000 hrs of running).

The problem with tracking down this error is that "It will be running along fine and then at an instant it will chew up ALL available resources."  I can not recreate this problem on demand. What I am trying to find out is what kind of things could create this error.
since there are to much street to walk there are some sugestions,

if you use DC (GetDC,CreateDC,etc) in your controls you must be sure to use some entries like ReleaseDC...

if you work with some Select Object maybe you need some DeleteObject...

if you use DLL and loudit dynamicly (LoadLibrary) you must use FreeLibrary... or FreeModule (16 bit only)...

if you use AllocGDIMem you must use FreeAllGDIMem...

if you use AllocMem you must use FreeAllMem...

if you use AllocUserMem you must use FreeAllUserMem...

if you use LoadResource you must use FreeResource...

if you use  GlobalAlloc or GlobalReAlloc you must use GlobalFree...


there are some calls that let you verify some memory isues...

VOID GlobalMemoryStatus(lpmstMemStat)

LPMEMORYSTATUS lpmstMemStat;//address of memory status structure

typedef struct _MEMORYSTATUS { /* mst */
    DWORD dwLength;        /* sizeof(MEMORYSTATUS)        */
    DWORD dwMemoryLoad;    /* percent of memory in use    */
    DWORD dwTotalPhys;     /* bytes of physical memory    */
    DWORD dwAvailPhys;     /* free physical memory bytes  */
    DWORD dwTotalPageFile; /* bytes of paging file        */
    DWORD dwAvailPageFile; /* free bytes of paging file   */
    DWORD dwTotalVirtual;  /* user bytes of address space */
    DWORD dwAvailVirtual;  /* free user bytes             */

you can use FIND to search for some of those function, and make a timer who verify memory balance (GlobalMemoryStatus) and then take actions around it...

I hope this will help you...
Are you using an exception handling mechanism?  If so, check for a possible loop.
What is it that this program is supposed to do?  
What external DLLs is it using?

By any chance are you using WinSock?  
I have seen this happen sometimes with applications that use WinSock.  In particular, Netscape 4.04 will go south in a really bad way every so often
dougcAuthor Commented:
Thank you for the comment zsi.

  Our program is a client server application. It is just a standard Windows 95/NT application thats purpose is for a Graphical User Interface. We're not using any external DLL's other than the standard windows ones. And we do use Winsock. Should we look to Winsock2 as an option?
Does this happen on all computers, or only on certain computers ? Does it happen on win95 or win95 oem2 ?

Maybe some windows system files is corrupt, or this is some hard to track bug in windows.

Try init and shutdown your winsock part in a loop and see if it crashes.

There was a network-related resource-leaking bug which Microsoft fixed with a kernel32.dll update. Try installing this kernel update and see if it still happens.
Does BoundsChecker report any error when you run it in debug mode for 1 hour and then close it?  If not, the problem is quite hard to trace, unless you post the code.

I would look to WinSock as the culpret.  While I cannot recall the article off-hand, Microsoft has acknowledged that there were some issues regarding resource problems identical to what you are experiencing.

I would suggest that you try another winsock library as an experiment.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I guess the problem of winsock (I have not read anything about that) only happens in some very race occasions, otherwise so many winsock applications like netscape, IE, IIS and my own application (which is also a server) will all have such problem.
Try installing the latest Winsock 2 from

I don't remember if this is *the* article that I read, but it certainly is *one* that addresses some problems with WinSock.

Winsock Function Calls Generate Non-Paged Pool Memory Leak

Last reviewed: January 5, 1998
Article ID: Q171996 The information in this article applies to:

•Microsoft Windows NT Workstation versions 3.51 and 4.0 •Microsoft Windows NT Server versions 3.51 and 4.0


If Winsock function calls are called in a tight loop such that a client application communicates with a local server executing a call sequence similar to

   socket, setsockopt, connection, send, closesocket

a nonpaged pool memory leak may occur.


Because the internal I/O-completion APC routines did not get a chance to run, the result was a non-paged pool memory leak. are the


To resolve this problem, obtain the hotfix below, or wait for the next service pack.


Microsoft has confirmed this to be a problem in Windows NT version 3.51. A supported fix is now available, but has not been fully regression tested and should be applied only to systems experiencing this specific problem. Unless you are severely impacted by this specific problem, Microsoft recommends that you wait for the next Service Pack that contains this fix. Contact Microsoft Technical Support for more information. receive

Microsoft has confirmed this to be a problem in Windows NT version 4.0. A supported fix is now available, but has not been fully regression tested and should be applied only to systems experiencing this specific problem. Unless you are severely impacted by this specific problem, Microsoft recommends that you wait for the next Service Pack that contains this fix. Contact Microsoft Technical Support for more information. receive
Unfortunately, he's running Win95 so the article does not apply.

Try installing Winsock 2.

I wouldn't be too sure.  I had a lot of WinSock-related memory leaks and they occured in Win95.
It is possible that winsock is to be blamed, but in most cases it is the bug of application itself

I do not agree with your statement.  If a dll (or some similar library) is not properly written and does not manage its own resources, than it does not matter how good your own code is.

And the problem that I referred to occured in several applications including IE 3, Netscape 3, and AOL.  The new version of WinSock was released and incorporated into these apps and the problen disappeared.

While it is possible that the problem might have existed in all of these programs at the same time, it is unlikely.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.