Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!think.com!barmar From: barmar@think.com (Barry Margolin) Newsgroups: comp.lang.c Subject: Re: freeing mallocs Message-ID: <1991Apr17.033134.6848@Think.COM> Date: 17 Apr 91 03:31:34 GMT References: <=-4_MX.@cs.widener.edu> Sender: news@Think.COM Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 25 In article <=-4_MX.@cs.widener.edu> sven@cs.widener.edu (Sven Heinicke) writes: ]question 26 of the FAQ is "How do I dynamically allocate a ]multidimensional array?". To deallocate a multidimensional array can ]I just do a: ] ] free(array); ] ]Or do I have to do this: ] ] for(i = 1;i < nrows; i++) ] free(array[i]); ] free(array); Good rule of thumb: you should call free() as many times as you called malloc(). This includes calls to malloc() that are done for you by library routines. Free(x) can only free as much stuff as was allocated by the call to malloc() that returned x. -- Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar