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

  1. Path: sparky!uunet!lhdsy1!kato.lahabra.chevron.com!hwrvo
  2. From: hwrvo@kato.lahabra.chevron.com (W.R. Volz)
  3. Newsgroups: comp.windows.x
  4. Subject: Re: Memory leaks
  5. Message-ID: <5529@lhdsy1.lahabra.chevron.com>
  6. Date: 29 Jul 92 23:42:07 GMT
  7. References: <9207291738.AA05158@mtesol>
  8. Sender: news@lhdsy1.lahabra.chevron.com
  9. Organization: Chevron Oil Field Research Company
  10. Lines: 31
  11.  
  12. In article <9207291738.AA05158@mtesol>, sinan@mtesol.boeing.COM (Sinan Karasu) writes:
  13. |> 
  14. |>  When is a memory leak a memory leak. If I do many malloc's with
  15. |> no dalloc's , does the memory remain leaked when the program exits?
  16. |> Is the answer different in different OSs such as Sun,SCO etc... ?
  17. |> Sinan
  18.  
  19. A memory leak, according to my definition occurs when the variable that
  20. hold a pointer goes out of scope before the pointer has been freed.
  21. For example
  22.  
  23. void leaky(void)
  24. {
  25. int *p;
  26. p = (int *) malloc(1000*sizeof(int));
  27. }
  28.  
  29. has a leak because p hasn't been freed prior to the functions return. Once
  30. returned, there is no way to free the memory since you don't know where the
  31. address is anymore.
  32.  
  33. There are many other specific ways of createing leaks, believe me.
  34.  
  35. -- 
  36.  
  37. ======================
  38. Bill Volz
  39. Chevron Oil Field Research Co.
  40. Exploration Research/Geophysics Division.
  41. P.O. Box 446, La Habra, CA 90633-0446
  42. Phone: (310) 694-9340
  43.