Re: Do memory allocations need to be freeed every time?
- From: rlb@xxxxxxxxxxxxxxxxxxxxxx (Richard Bos)
- Date: Thu, 19 Jun 2008 10:24:28 GMT
viza <tom.viza@xxxxxxxx> wrote:
On Thu, 19 Jun 2008 02:23:05 -0700, Ravindra.B wrote:
Is freeing the allocated memory is really required every time, for a
program like this as freeing doesnâ??t bring in any change w.r.t memory
space (or) will it become a memleak some where down the line if it is
not freeed?
To avoid memory leaks, for each and every time you call malloc(), you
must call free() exactly once with the same pointer that was returned.
The only exceptions to this are:
1) if the call to malloc() returned NULL
2) if you are about to immediately terminate the program anyway*
And even in those cases, you _may_ call free(), and it is often
considered good style (and particularly in the first case, can simplify
your code) if you do.
Richard
.
- References:
- Do memory allocations need to be freeed every time?
- From: Ravindra.B
- Re: Do memory allocations need to be freeed every time?
- From: viza
- Do memory allocations need to be freeed every time?
- Prev by Date: Re: Do memory allocations need to be freeed every time?
- Next by Date: CD DVD Recovery Toolbox Free
- Previous by thread: Re: Do memory allocations need to be freeed every time?
- Next by thread: Re: Do memory allocations need to be freeed every time?
- Index(es):
Relevant Pages
|