free (C System Call)

free is a system call that is used to release memory back to the Operating System that was allocated by malloc, calloc or realloc. If the argument is NULL, no action is taken.

Required Include Files

#include <stdlib.h>

Function Definition

void free(void* pointer);
Field Description
void* pointer The memory address to be returned to the Operating System

Code Snippet

Example closing an open file descriptor:

#include <stdlib.h>
 
int main()
{
    char* buffer = malloc(1024);
    if (buffer == NULL)
        return 1;  /* error */
 
    free(buffer);
    return 0;  /* success */
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License