Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

program hanging after termination

Status
Not open for further replies.

michaelkrauklis

Programmer
Dec 5, 2001
226
US
I have the following problem. My program hangs terribly once it has finished execution. The longer the program executes the longer it hangs at the end. Could a memory leak cause this problem?? If not then what's going on?
Code:
...

	standardExecute("session");

	std::cout<<&quot;back in main&quot;<<endl;

	/*end testing*/
	return nRetCode;
}
That is the end of my main function. The standardExecute function completes, the program prints out &quot;back in main&quot; and then the CPU spikes to 100% and just sits there perportionally to how long the program has been running. If the program only ran for five minutes it hangs for about a minute. Then finishes execution. I am still in debug mode... might that have anything to do with this? MYenigmaSELF:-9
myenigmaself@yahoo.com
 
To have a general idea of whether a lot of memory is being leaked, watch the memory usage as the program executes (assuming you're on NT or 2000 or XP). Does it gradually increase as the program continues executing? When running in debug mode, does Visual Studio report any memory leaks when the program terminates?

Or, are you allocating a lot of memory and/or objects? Are there any &quot;automatic&quot; disk saves and/or other completion processing associated with any of your objects before or during destruction?

&quot;State your designation...&quot; (err, sorry, I was thinking of 7 of 9), I mean, what's the nature of your program and what resources does it use?
 
The memory rises silghtly but it is within the limits that I would expect it to be. Right now I'm running on a test machine. WinNT,450MHz,128Mb. But the production server has dual gig processors and a gig of ram. The part of the program that I'm working on right now is taking delimited text from a file and creating a structure to it in my program. Then I am exporting it to a MsSQL2k server using ODBC. I didn't check for memory leaks in the debugger and I can't until monday. We have a process that runs durring the weekend that takes 72 hours, consequently the program I'm writing is supposed to take this program's place. And am I allocating a lot of objects... that's kind of relative isn't it? Most of my experience is in Java where everything is objects. I would say I'm using a lot of objects but most are simple like CStrings and CMaps. And as I said, I don't think the memory usage is that big. I'll get back to you on monday once I can run my program again. Thanks a lot for the input. MYenigmaSELF:-9
myenigmaself@yahoo.com
 
Another guy I work with said he had something similar happen...

As the program ended, there was a &quot;tight loop&quot; that executed while waiting for a port to close, which caused a delay and the processor to peak out.
 
First off, what is a &quot;tight loop?&quot; Secondly, I debugged a little and VC++ doesn't say that there are any memory leaks. I have variables who's values show up as red but I assume that just means that the values have changed. Am I correct in this assumption? In any respect, my memory is climbing more than it should be, but I can't figure out why. The debugger doesn't say I have any memory leaks and I can't find any in my code. Any advice? MYenigmaSELF:-9
myenigmaself@yahoo.com
 
Sorry... a &quot;tight loop&quot; is a while loop (used for waiting for some condition, in my friend's case, waiting for a port to close) without some sort of &quot;sleep&quot; statement and reasonable value within the loop, which resulted in racing through the loop, testing the port over and over again every split second and the processor resources being tied up unnecessarily.

You're correct about red values indicating variables that have changed.

Are you sucking the entire file into memory before uploading to the db via ODBC? Are there strings that are getting longer and longer (being appended and reallocated over and over again?) Does your program create large arrays of:

- strings
- structures
- objects?

If so, how complex are the structures or objects in the array (do they contain other arrays of structures, objects or even arrays)? Upon destruction, do all of these nested objects have to unwind and destroy a large number of objects and/or memory allocations?

Does your program write the data it reads back to another file and/or update the original file at the end of processing?

Sorry if this is like 20 questions. I'm just trying to think of something that might trigger a helpful idea. I may not have anything to add, but maybe someone else will???
 
One more thing, for debugging purposes, you may want to add logging with timestamps, for example, in each destructor (or near each free) to see if destroying objects is what is time-consuming... or wherever else you suspect the problem could possibly be (file open, i/o and close)???

You can surround these logging statements with #ifdef _DEBUG (and #endif) or some other flag you temporarily define so that the logging doesn't slow down your release version assuming you've found and fixed the problem.
 
Ok, eariler I had it so that I read the entire file into memory and then sent it to my database. I've changed this, however, and now I read the file in line by line (or row by row), send it to my database using ODBC, then destroy the object I create which represents the parsed row. So long as I keep the ODBC connection open this is a pretty fast process. It's a bit more complicated than that, but for the most part this is it. And the problem is in the parsing of the string. When I comment out all the ODBC stuff I still get the same problem. I can't find where the exact problem is because everything is so inter-related. I made my program modular but the modular chunks are pretty big. And the hanging at the end, it seems like it's windows trying to get back all the lost memory or something. In debugging mode it prints out all these messages about bits and whatnot and slowly the memory goes down. So fix the memory leak and that should fix the hanging problem. Easier said than done. And there's not really a portion of my code that's time consuming. It's all pretty quick. I've taken a process that used to take 72 hours and brought it down to about 30 minutes. Thanks for the help. If you've got any more suggestions don't hesitate. Thanks! MYenigmaSELF:-9
myenigmaself@yahoo.com
 
um... here's something interesting. Once my program terminated it randomly printed out(I know it's not random, but seemingly random)102A2770. Haha, I have no idea what's going on. I want to just start over. MY[red]enigma[/red]SELF:-9
myenigmaself@yahoo.com
 
haha, so I think I found the problem. well I got rid of the hanging problem by removing all usage of calloc and realloc from my code and just using CString functions/operators. And through some testing I've come to realize that the memory leak isn't in my program. Or at least I don't think it is. Why I say this is now, when my program completes execution I don't get any memory back at all, and SQL Server is using hundreds of megs of virtual memory, so I think it's a problem in SQL Server or windows or something. Now at least I have a new problem to work on:) Thanks for your help! MY[red]enigma[/red]SELF:-9
myenigmaself@yahoo.com
 
Yep, I feel pretty stupid. I don't have any memory leak. My program uses about 4 megs of memory. Everything else is being eaten up by SQL Server. I've basicaly wasted a day of my life... but I guess I did learn a little something. And at least the program isn't hanging anymore!
Thanks again for your input!! MY[red]enigma[/red]SELF:-9
myenigmaself@yahoo.com
 
Gee, Wally... how'd you get yourself through that one?

I feel like I was just a good listener to a man on a mission. |-0

Congratulations!
The Beav
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top