http://www.cplusplus.com/reference/cstdlib/free/
free
void free (void* ptr);
A block of memory previously allocated by a call to malloc, calloc or realloc is deallocated, making it available again for further allocations.
If ptr does not point to a block of memory allocated with the above functions, it causes undefined behavior.
If ptr is a null pointer, the function does nothing.
Notice that this function does not change the value of ptr itself, hence it still points to the same (now invalid) location.
Parameters
Return Value
none
Example
|
|
This program has no output. It just demonstrates some ways to allocate and free dynamic memory using the C stdlibfunctions.
Data races
Only the storage referenced by ptr is modified. No other storage locations are accessed by the call.
If the function releases a unit of storage that is reused by a call to allocation functions (such as calloc or malloc), the functions are synchronized in such a way that the deallocation happens entirely before the next allocation.
Exceptions (C++)
No-throw guarantee: this function never throws exceptions.
If ptr does not point to a memory block previously allocated with malloc, calloc or realloc, and is not a null pointer, it causes undefined behavior.
See also
- malloc
- Allocate memory block (function )
- calloc
- Allocate and zero-initialize array (function )
- realloc
- Reallocate memory block (function )