🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2362

Re: Freeing Memory

#2362
From: William Kaufman
Date: Sat, 23 Mar 1996 06:45
35 lines
1819 bytes
In article <4io1ks$nr1@solutions.solon.com> Daniel L Mills <dmills@eng.umd.edu> writes:
] 
] I'm having problems freeing a 3-D malloced array.  I thought I was doing
] it right but when I examine that status of the program's execution I
] notice that each time I reinitialize th array, the old memory does not
] get released.

    From the comp.lang.c FAQ:

7.25:	I have a program which mallocs and later frees a lot of memory,
	but memory usage (as reported by ps) doesn't seem to go back
	down.

A:	Most implementations of malloc/free do not return freed memory
	to the operating system (if there is one), but merely make it
	available for future malloc() calls within the same program.

    Chances are, it shouldn't grow by much, as long as the array size(s)
are consistent or decreasing.

]     for(i=0;i < icount; i++){
]         for(j=0; j < jcount; j++)
]            if((*nodearray)[i][j])
]                free((*nodearray[i][j]);
]         if((*nodearray)[i])
]             free((*nodearray)[i]);
]     }

    Note that, if ((*nodearray)[i]) is NULL, the stuff in the loop will
fail.  You should move this test outside the double "for"-loop.

                                           -- Bill K.

Bill Kaufman,          | "People look better under arrest,...it gives you
wkaufman@us.oracle.com |  an aggressive fashion look."  -- John Waters
Technical Details
Message-ID: <4j06lc$7uj@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4io1ks$nr1@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: wkaufman@us.oracle.com (William Kaufman)
Newsgroups: comp.lang.c.moderated
Subject: Re: Freeing Memory
Date: 23 Mar 1996 00:45:00 -0600
Organization: Oracle Corporation, Redwood Shores CA
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4j06lc$7uj@solutions.solon.com>
References: <4io1ks$nr1@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com