Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Statistics needed on memory leaks for chess programs

Author: Heiko Mikala

Date: 18:07:01 12/29/98

Go up one level in this thread



On December 28, 1998 at 22:23:58, Robert Hyatt wrote:

>On December 28, 1998 at 18:26:47, KarinsDad wrote:
>>On December 28, 1998 at 17:50:59, Inmann Werner wrote:
>>>Try to use some Microsoft Compilers (C++, Foxpro..). If you run some of the
>>>"sample applications" again and again, you will see the decreasing memory!
>>>I hate it, cause I have to do with it every day.
>>>Most problem is, if you create an object in the running program. Then you kill
>>>the "father". Take a look!
>>I was trying to re-create what I have seen before and was unsuccessful. I
>>could create memory leaks with no problem, but the OS always cleaned it
>> back up when the application exited (as is proper). Please let me know
>>which sample C++ applications you were using, which "father" objects you
>>destroyed, and on which OS.
>
>I don't follow any of this.  IE in crafty, I "malloc()" the hash tables, I
>do _not_ free() them before I exit(0) the program.  And the memory gets freed
>up under windows just as it does under linux.  Yes I can create a thread and
>so long as a thread "lives" its resources remain allocated.  But I don't know
>of commercial chess programs that create threads so don't see where this is a
>problem.
>
>this "object" discussion loses me.  An object (in C++) is not a permanent thing
>that exists 'on its own'... it is simply a data structure that comes into being
>when you access an object constructor, and disappears when you access the
>destructor...  but when the program terminates, the objects disappear along
>with it...

I think there's some confusion going on here. I agree with you, that there
should
be absolutely no problem with dynamically allocated data, be it by using malloc
or by using the new operator in C++ to allocate objects. And I haven't had such
problems in Win95. But there *is* a problem when using system resources, esp.
graphics resources like device contexts, pens, brushes, fonts and so on.
First of all, the number of device contexts (and some other resources) is
limited.
Secondly, to use graphic objects, you have to select these objects into a device
context *and*, after using it you have to deselect it (and restore the object
that
was in use before). But this is something many programmers forget, especially
programmers who are new to Windows programming. And if you forget to
deselect these objects you'll get into deep trouble... This problem was a much
bigger one in 16-Bit Windows times, because GDI resources were even more
limited at that time. Also, the MFC has a mechanism that tries to free resources
automatically, if they seem to be unused (not used for some amount of time).
It's
hidden and undocumented and killed some of my applications... :-( But still, at
least in Win95 (don't know about NT), this problem exists, and these resources
*don't* get freed automatically after program termination!

This may be the problem with CB7, which was described in the beginning of
this thread.

Greetings,

Heiko.



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.