home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / windows / x / 14619 < prev    next >
Encoding:
Internet Message Format  |  1992-07-30  |  2.2 KB

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