Hello,

This is a question I have in mind for long but still haven't found the
answer yet. I hope anyone could give me some clarity in this.

There are many library functions that returns dynamically allocated
data. For example a function like this

char *createSomeData()
{
char *c = malloc(10000);
return c;
}

And then it is called somewhere...
char *c = createSomeData();

The question is, when will the data be freed? Or should we free it
ourselves, but I have never seen a C code that frees a pointer
returned by some function. For example, there are many win32 api
functions that takes a struct pointer as an argument. The struct must
have been dynamically allocated in the api function, but I have never
seen any instruction to free the struct returned when we no longer
need the struct.

Thanks.

Reply via email to