Defined in header <stdlib.h> | ||
void free(void*ptr); | ||
Deallocates the space previously allocated bymalloc(),calloc(),aligned_alloc(),(since C11) orrealloc().
Ifptr is a null pointer, the function does nothing.
The behavior is undefined if the value ofptr does not equal a value returned earlier bymalloc(),calloc(),realloc(), oraligned_alloc()(since C11).
The behavior is undefined if the memory area referred to byptr has already been deallocated, that is,free(),free_sized(),free_aligned_sized()(since C23), orrealloc() has already been called withptr as the argument and no calls tomalloc(),calloc(),realloc(), oraligned_alloc()(since C11) resulted in a pointer equal toptr afterwards.
The behavior is undefined if afterfree() returns, an access is made through the pointerptr (unless another allocation function happened to result in a pointer value equal toptr).
A call to | (since C11) |
Contents |
| ptr | - | pointer to the memory to deallocate |
(none)
The function accepts (and does nothing with) the null pointer to reduce the amount of special-casing. Whether allocation succeeds or not, the pointer returned by an allocation function can be passed tofree().
| allocates memory (function)[edit] | |
(C23) | deallocates previously allocated sized memory (function)[edit] |
(C23) | deallocates previously allocated sized and aligned memory (function)[edit] |
C++ documentation forfree | |