Do memory allocations need to be freeed every time?



I have declared a global variable which is array of pointers and
allocated memory for each array variable by using malloc. Some thing
similar to below...

static char *arr[10];

main()
{
int i;

for(i = 0; i < 10; i++)
arr[i] = malloc(sizeof(char));

……..

}

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?

Thanx,
Ravindra. Bhadramraju
.



Relevant Pages

  • Re: Do memory allocations need to be freeed every time?
    ... allocated memory for each array variable by using malloc. ... program like this as freeing doesn’t bring in any change w.r.t ... jacob at jacob point remcomp point fr ...
    (comp.lang.c)
  • Dynamic Memory Allocation
    ... Local variable which are pointers and have dynamically allocated ... Actually, i want to develop an API, which will help in collection ... (plz correct me if i'm wrong). ... how to proceed to get information about dynamically allocated memory. ...
    (comp.lang.c)
  • Re: why is casting malloc a bad thing?
    ... P.J. Plauger wrote: ... > There's no requirement that a malloc call return a pointer ... Is a piece of memory allocated by malloc required to be aligned ... Subclause 7.10.3 requires allocated memory to be suitably aligned ...
    (comp.lang.c)
  • Re: To use global variables or no????
    ... Why not use allocated memory? ... How does malloc() remember where its skiplist starts? ... The malloc function puts a struct into a skiplist with an auto root node at ... memory is returned to the operating system. ...
    (comp.lang.c)
  • Re: Dynamic Memory Allocation
    ... Local variable which are pointers and have dynamically allocated ... (plz correct me if i'm wrong). ... how to proceed to get information about dynamically allocated memory. ... Try to study the internals of existing GCs like Boehm's ...
    (comp.lang.c)