Archived

This topic is now archived and is closed to further replies.

kindfluffysteve

aghh! my program wont work on XP.

Recommended Posts

any ideas why a console app written in windows ME will crash on windows XP sporadically after 5-10 minutes. This is how my system works.. there is a batch file which goes like this: loop: update.exe (to check a server for an update) client.exe (this does the work) goto loop and on ME or 98 it runs for hours, and infact it never seems to crash at all. but on XP - crash a minute. There are no compiler warnings in the code other than warnings about unreferanced variables - which is fine, no linker warnings.

Share this post


Link to post
Share on other sites
Win2K and WinXP both, I think, just launch executables rather than run them, ie: it does not wait for the command to complete.

This means that update.exe is launched, and while it''s still running, client.exe is launched, then possibly while they''re both still running, update.exe is launched again, and client.exe again, etc.

There''s innovation for ya!

Share this post


Link to post
Share on other sites
hmmmm, nah i dont believe that. at least in windows prof - the server there uses this to shut itself down and restart - a looping batch file.

a question - is it safe to assume that windows XP will deallocate memory that has leaked or not been freed by my app after exit(0). ???

Share this post


Link to post
Share on other sites
quote:

a question - is it safe to assume that windows XP will deallocate memory that has leaked or not been freed by my app after exit(0). ???



I believe the only way to deallocate memory leaks after an app closes is to restart your system. I don''t think there is a way to get that memory back without restarting your system.. I could be wrong though, but that is my understanding of why it is important to cleanup your memory allocations before you exit.

Share this post


Link to post
Share on other sites
Memory leaks should be cleaned, since the pages they are allocated from are associated with the process. When the process dies, the pages are marked as available again, regardless of what the application did with them.

Relying on this behaviour is unadvisable : if some page is held by a dynamic library, it will not be released until the library itself is unloaded. If the library happens to stay in memory even after the process terminates, for example because it is shared by several processes (as the windows core libraries are), the resources will remain ''leaked''.

Such resource leaks (anything with a HANDLE, shared memory blocks and other system-global objects) are much more fearsome than ''ordinary'' memory leaks and cannot even necessarily be reported by a heap tracker (unless you use a special build of the library itself !)


[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]

Share this post


Link to post
Share on other sites
quote:
I believe the only way to deallocate memory leaks after an app closes is to restart your.


I suggest you read documentation before posting crap.

The ONLY memory staying allocated ais stuff like shared memory and other things that can not be automatically deleted by the system.


Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

Share this post


Link to post
Share on other sites
quote:
Original post by kindfluffysteve
a question - is it safe to assume that windows XP will deallocate memory that has leaked or not been freed by my app after exit(0). ???

As stated allocated memory gets freed once the process goes away.

WinNT based OS''s keeps a list of all handles opened by a process. Once a process dies, for whatever reason, all these handles get their referance counts decreased. However this is only for system objects locally used by the process(Memory mapped files, mutexs, etc).

Thus is you get a handle from a library(directly or indirectly) which comunicates to another process to allocate the handle, and the process dies with out releasing the handle, that handle will leak.

However you are garrenty that allocated *Memory* will be freed, no matter how an app dies. Delphi uses this when it programically generates stub window procs to correctly call the window proc defined in a class.

Share this post


Link to post
Share on other sites
I just did a couple experiments, and you need to first off change your loop label from: "loop:" to ":loop".

Below is the help on goto, make sure you try "calling" the programs too, I don't think you are supposed to use call to call programs, but it is worth a shot.


C:\Documents and Settings\Sysop>help goto
Directs cmd.exe to a labeled line in a batch program.

GOTO label

label Specifies a text string used in the batch program as a label.

You type a label on a line by itself, beginning with a colon.


If Command Extensions are enabled GOTO changes as follows:

GOTO command now accepts a target label of :EOF which transfers
control to the end of the current batch script file. This is an
easy way to exit a batch script file without defining a label.
Type CALL /? for a description of extensions to the CALL
command that make this feature useful.


"C makes it easy to shoot yourself in the foot; C++ makes it harder, but
when you do, it blows away your whole leg."

- Bjarne Stroustrup

Realm Games Company

[edited by - yummy_potatoes on March 2, 2003 12:16:44 PM]

Share this post


Link to post
Share on other sites