Solved

Resource Problem

Posted on 1998-04-27
26
273 Views
Last Modified: 2013-12-03
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.
0
Comment
Question by:dougc
  • 6
  • 5
  • 4
  • +7
26 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1397334
How are you sure that it is your application? Is this under Win95 or NT?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1397335
What sort of resources are your talking about?  How do you know it is running out of these resources?
0
 

Author Comment

by:dougc
ID: 1397336
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.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1397337
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.
0
 

Author Comment

by:dougc
ID: 1397338
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.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1397339
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.
0
 
LVL 2

Expert Comment

by:happy1
ID: 1397340
Hi, Dougc

I think I know what will help U -
go to this site :

http://www.stratosware.com/
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
application.

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
debuggers...)

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
0
 

Author Comment

by:dougc
ID: 1397341
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??
0
 
LVL 22

Expert Comment

by:nietod
ID: 1397342
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?
0
 

Author Comment

by:dougc
ID: 1397343
Adjusted points to 1000
0
 
LVL 1

Expert Comment

by:jbabcock
ID: 1397344
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...)
0
 

Author Comment

by:dougc
ID: 1397345
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.
0
 
LVL 2

Expert Comment

by:lortega
ID: 1397346
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...


'****************************************************
finaly...

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             */
} MEMORYSTATUS, *LPMEMORYSTATUS;

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...
lortega
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 11

Expert Comment

by:alexo
ID: 1397347
Are you using an exception handling mechanism?  If so, check for a possible loop.
0
 
LVL 4

Expert Comment

by:zsi
ID: 1397348
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
0
 

Author Comment

by:dougc
ID: 1397349
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?
0
 
LVL 3

Expert Comment

by:byang
ID: 1397350
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.
0
 
LVL 7

Expert Comment

by:faster
ID: 1397351
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.
0
 
LVL 4

Accepted Solution

by:
zsi earned 1000 total points
ID: 1397352
dougc,

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.

zsi
0
 
LVL 7

Expert Comment

by:faster
ID: 1397353
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.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1397354
Try installing the latest Winsock 2 from www.microsoft.com
0
 
LVL 4

Expert Comment

by:zsi
ID: 1397355
dougc,

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

zsi
==============================================
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







SYMPTOMS

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.





CAUSE

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





RESOLUTION

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





STATUS

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
0
 
LVL 11

Expert Comment

by:alexo
ID: 1397356
Unfortunately, he's running Win95 so the article does not apply.

Try installing Winsock 2.

0
 
LVL 4

Expert Comment

by:zsi
ID: 1397357
I wouldn't be too sure.  I had a lot of WinSock-related memory leaks and they occured in Win95.
0
 
LVL 7

Expert Comment

by:faster
ID: 1397358
It is possible that winsock is to be blamed, but in most cases it is the bug of application itself
0
 
LVL 4

Expert Comment

by:zsi
ID: 1397359
faster,

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.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now