Computer Chess Club Archives


Search

Terms

Messages

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

Author: Eugene Nalimov

Date: 22:56:40 12/27/98

Go up one level in this thread


On December 28, 1998 at 00:32:18, KarinsDad wrote:

>On December 27, 1998 at 21:53:34, Robert Hyatt wrote:
>
>>On December 26, 1998 at 23:58:26, Komputer Korner wrote:
>>
>>>On December 24, 1998 at 09:42:11, KarinsDad wrote:
>>>
>>>>On December 24, 1998 at 03:22:36, Komputer Korner wrote:
>>>>>in WIN 95 without CB7 running I had 93% system resources free. After running CB
>>>>>7 it went down to 76%. After closing CB 7 it went back to only 89%, so a clear
>>>>>memory leak.
>>>>>--
>>>>>Komputer Korner
>>>>
>>>>KK,
>>>>
>>>>That is one of my pet peeve's. It takes a day or two (no big deal) to clean up
>>>>code so that it doesn't have memory leaks. A memory leak is a bug like any other
>>>>bug, it just happens to affect your overall system as opposed to the product
>>>>itself.
>>>>
>>>>Do you happen to have any statistics on which chess programs, databases,
>>>>training tools, etc. have or do not have memory leaks?
>>>>
>>>>It would be good for everyone to know this. Especially for those people running
>>>>chess programs in tournaments or across the net (e.g. I went looking into CB7
>>>>for something just before the tournament, forgot to reboot, and my program's
>>>>hash table wasn't as large because of it).
>>>>
>>>>Happy Holidays,
>>>>
>>>>KarinsDad
>>>
>>>good idea. I am too busy writing an article on CA 4 right now but if everybody
>>>would do a test on their favourite chess program we should get answers.
>>>--
>>>Komputer Korner
>>
>>You are looking in the wrong place for this "leak".  If a program exits, and
>>resources are not freed up, it is _not_ the program that is at fault, it is the
>>underlying operating system that is screwed up.  Because once a process exits,
>>it is up to the operating system to release memory allocated by the process.
>>
>>I know of no way for a user program to cause such a problem unless the operating
>>system is hosed.  IE this can't happen under linux unless a bug in the linux
>>kernel shows up...  and we don't have many of those thankfully...
>
>This is probably true with linux. I'll ask my partner as he is a major linux
>supporter. However, the original posting was talking about Windows 95. In
>Windows 95, 98, and NT, the OS is not designed properly to recover resources
>(yes, Microsoft will tell you that it is, but all of these OSs do a poor job of
>it). In fact, the Visual C++ compiler is designed to not recover resources (such
>as objects) so that programmers can do some tricky things. However, I know of
>nobody who has that kind of talent (or at least uses it in that manner), hence,
>it would be nice if the compiler (or minimally the OS) allowed the option of
>recovering resources automatically without having to go through the hassle of
>double checking your code. Since this is not the case, you must go through that
>step. Any object you create, you must destroy. I believe that memory deallocates
>automatically better than objects and the C compilers are probably better than
>the C++ compilers.
>
>In fact, Microsoft recommends that you reboot your system every two hours. Why?
>Because it can become unstable since running multiple applications which have
>not been checked for memory leaks will almost invariably leak. Eventually, there
>would not be enough memory left to run a single application.
>
>The idea of having statistics on which chess applications have memory leaks and
>which do not is worthwhile (at least until the Microsoft compilers and OSs catch
>up with the rest of the world).
>
>Regards,
>
>KarinsDad

First, it looks that you confused 2 different concepts:
(1) dynamic memory allocation, and (2) usage of the memory
and other OS resources.

Yes, that's true, both C and C++ do not use garbage
collectors (if you are not using some 3rd party library -
and all those libraries are dangerous enough). In those
languages you have to manually free memory that you don't
use anymore. Java forces you to use garbage collector.
Theoretically that means that Java program will contain
less memory-related bugs. In practice, it usually contains
enough bugs of the different kind - programmers are very
inventive creatures, they find very interesting ways to
introduce bugs in the program.

I guarantee that all memory that was allocated by calls
to malloc() in C (or new() in C++) will be deallocated
when the program will exit. That will happen in any 32-bit
Windows, be it Win9x or WinNT. Usual problem is that often
programmer forgets to shut down one of the threads
(parallel programming is much more complex than the
sequental one), so from the OS perspective program is not
terminated. Unfortunately, usually that's not the GUI thread,
so user have to look at the active process list to understand
what happens. Average user cannot do that... In that case
computer reboot will really help - after reboot those
applications will not start automatically. BTW, something
similar can happen with Unixes, too. When I uploaded TBs
to Bob's machine, several times his FTP server (or must I
call it client?) hangs after connection was reset, and
continued to run (and occupied memory in the swap partition)
till Bob killed it. It looks that it uses maximum several
MBs of memory, and/or Bob has large swap partition.
Otherwise, after several disconnects Bob's machine would be
totally paralyzed - exactly what happens when you run
badly-written Windows application(s). And there are much
more badly written applications for Windows than for Unix...

Simpler problems occur when chess program constantly
allocate memory and don't free previously allocated
memory that is now unused. For example, program can
allocate some buffers in the beginning of the each game,
and don't free them before the next one. In that case you'll
see that program uses more and more memory, and that
eventually will affect other applications (if any) running
on the computer. Here simple program restart will help.
But again, that's problem in the specific application, not
in the OS itself.

Other possible source of troubles is the fact that for
compatibility reasons Windows 9x is a mix of 16-bit and
32-bit code. There are much less 16-bit resources (e.g.
memory) than 32-bit resources. You easily can run out of
"low" memory and have tens of megabytes of free "high"
memory that cannot be used by the 16-bit application(s).

When I generated TBs, I run WinNT machine for a months
without single reboot, and I had not meet any problems,
other than my own bugs...

Eugene

PS. The text above is my own opinion, not the official
    position of the Microsoft corporation.



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.