Can you release the memory of an array defined with static allocation?
-
why do you ask and in what language?Andy Dent– Andy Dent2009-11-23 02:49:29 +00:00Commented Nov 23, 2009 at 2:49
-
I'm learning C++ right now . . . and I am just trying to see if this was possible.Brandon Tiqui– Brandon Tiqui2009-11-23 03:20:34 +00:00Commented Nov 23, 2009 at 3:20
5 Answers
No, it is not possible to de-allocate statically allocated memory.
Depending on the language (for example C/C++, using pointers) you may be able to use the memory held by this array for other purposes, but doing so will only re-use the memory; memory won't be released per-se.
This said, this idea of reusing static memory for / with variables other than the variables originally defined there, is only suggested to help understand the nature of this type of allocation. In practical terms, and in particular as a novice, it makes absolutely no sense to have the need for such a feature:
- either the variable is expected to have a lifetime as long as the program
at which case it should be declared static - or the variable is not going to be needed at some time during program execution
at which case it should be dynamically allocated (? shortly after/during program initialization) and released whenever appropriate.