home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!lhdsy1!kato.lahabra.chevron.com!hwrvo
- From: hwrvo@kato.lahabra.chevron.com (W.R. Volz)
- Newsgroups: comp.windows.x
- Subject: Re: Memory leaks
- Message-ID: <5529@lhdsy1.lahabra.chevron.com>
- Date: 29 Jul 92 23:42:07 GMT
- References: <9207291738.AA05158@mtesol>
- Sender: news@lhdsy1.lahabra.chevron.com
- Organization: Chevron Oil Field Research Company
- Lines: 31
-
- 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
-
- A memory leak, according to my definition occurs when the variable that
- hold a pointer goes out of scope before the pointer has been freed.
- For example
-
- void leaky(void)
- {
- int *p;
- p = (int *) malloc(1000*sizeof(int));
- }
-
- has a leak because p hasn't been freed prior to the functions return. Once
- returned, there is no way to free the memory since you don't know where the
- address is anymore.
-
- There are many other specific ways of createing leaks, believe me.
-
- --
-
- ======================
- Bill Volz
- Chevron Oil Field Research Co.
- Exploration Research/Geophysics Division.
- P.O. Box 446, La Habra, CA 90633-0446
- Phone: (310) 694-9340
-