Quick question about freeing up allocated memory.

I have a random question about memory allocation. If you allocate memory to a local variable and do not free it during the program because you don't think you'll need it and the program exits will this memory be freed?
And if it is freed, does the same apply for a static variable?



Am new to this programming stuff so am real sorry if am asking a stupid or an obvious question.
All memory is freed when a program exits. It is bad to allocate memory in a local variable and not deal with it at some point. If you're going to use the locally-allocated memory outside of the calling function, you will have to return the address (through a parameter or via return) and then free it when you are through.

Static variables work the same way (they are freed when the program exits.)
Topic archived. No new replies allowed.