home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 1658 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: senator-bedfellow.mit.edu!red-branch!rid
  2. From: rid@red-branch.MIT.EDU (Shawna Grimm)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Must I free my linked lists? (GCC)
  5. Date: 22 Jan 1996 15:52:54 GMT
  6. Organization: Massachvsetts Institvte of Technology
  7. Message-ID: <4e0bsm$rkb@senator-bedfellow.MIT.EDU>
  8. References: <4dudic$aif@vixen.cso.uiuc.edu> <4dusp9$7k3@senator-bedfellow.MIT.EDU> <4dvn6t$lc3@hamilton.maths.tcd.ie>
  9. NNTP-Posting-Host: red-branch.mit.edu
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. David Malone (dwmalone@maths.tcd.ie) typed in the following on 22 Jan 1996 09:59:57 -0000:
  13. : rid@red-branch.MIT.EDU (Shawna Grimm) writes:
  14.  
  15. : >Unknown (Dannyman@uiuc.edu) typed in the following on 21 Jan 1996 22:09:16 GMT:
  16. : >:    I'm writing a program that makes use of dynamic memory allocation through
  17. : >: linked lists using malloc() ... from an implementation PoV there's no need
  18. : >: to flush this stuff as after the queue is created it's output and the
  19. : >: program exits. My question is;
  20.  
  21. : >Yes, you _should_ free any memory that you allocate in your program. 
  22. : >Memory that is allocated and not freed will not be returned to the system 
  23. : >unless you turn the machine off, so if you want your memory back, you 
  24. : >must free it. Personally, I would prefer to use AllocMem() or AllocVec()
  25. : >(with FreeMem() and FreeVec() ofcourse).
  26.  
  27. : I think the memory is freed in when you use malloc - in gcc or SAS/C.
  28. : Weither this is in malloc's spec is another matter. I think
  29. : memory you malloc ( as opposed to AllocMem'ed ) seems to be tracked
  30. : and freed at exit. I noticed this when I was testing something I was
  31. : writing on unix, and hadn't finished the memory stuff. It allocates
  32. : about 8MB, which went fine, but I was quite shoked to see that I could
  33. : run it twice in a row ( I only have 10MB of ram ).
  34.  
  35. :     David.
  36.  
  37. I cannot confirm or deny this, as I don't have my amiga up and running at 
  38. the moment, BUT, it is considered 'good programming' to free up all 
  39. memory you have dynamically allocated. So, to keep your nose clean, 
  40. free() alled malloc()'ed/calloc()'ed memory.
  41.  
  42. * Lars M. Hansen
  43.  
  44.