home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!lsl!snail
- From: snail@lsl.co.uk
- Newsgroups: comp.windows.x
- Subject: Re: Memory leaks
- Message-ID: <1992Jul30.122716.2199@lsl.co.uk>
- Date: 30 Jul 92 11:27:16 GMT
- References: <9207291738.AA05158@mtesol>
- Organization: Laser-Scan Ltd., Cambridge
- Lines: 37
-
- In article <9207291738.AA05158@mtesol>, sinan@mtesol.boeing.COM (Sinan Karasu) writes:
- >
- > When is a memory leak a memory leak. If I do many malloc's with
- > no dalloc's , does the memory remain leaked when the program exits?
- > Is the answer different in different OSs such as Sun,SCO etc... ?
- > Sinan
-
- When a program starts it is given it's own stack space and it's own heap space.
- Memory is allocated in the heap space. When the program exits, the stack space
- and the heap space are passed back into the OS's hands. You do not leak
- memory this way. This is even true for MSDOS, since you only ever have one
- main program, and all TSRs should be well behaved and not grab memory and
- leave it lying around. For UNIX and VMS you'll be OK. If you access memory
- outside the stack or heap or BSS space then you'll get a segmentation fault or
- access violation and you program will enter it's signal handler and probably
- die (ie: You'll know about it!)
-
- The answer for MSDOS and GEMDOS/TOS (Atari ST) can be more complicated, since
- the program effectively
- has access to the whole memory of the computer, but can actually tell the
- OS that it only wants some of the memory, and gives it back to the OS. The
- program can then ask for more if it need more later (by doing a DOS level
- call rather than a malloc etc). What happens if the program does this and then
- exits I don't know (ie Is that last DOS level call freed? I don't think it is..
- I think you'd have to explicitly do another DOS level call). Anyway you don't
- use MSDOS or GEMDOS/TOS anyway do you?
-
- On MSDOS if you access memory outside the heap/stack/bss areas then chances are
- you'll clobber one of the expansion cards or low memory and overwrite the
- CMOS RAM that configures the computer (yes I've done this too, with a rogue
- mouse driver program) and most likely hang the computer (RESET time)
-
-
- OK, thats enough, not exactly X WINDOWS is it?
-
- Stephen Kellett
- snail@lsl.co.uk
-