Skip to content

Latest commit

 

History

History
69 lines (55 loc) · 3.52 KB

File metadata and controls

69 lines (55 loc) · 3.52 KB
title ms.custom ms.date ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic apiname apilocation apitype f1_keywords dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
free | Microsoft Docs
11/04/2016
cpp-standard-libraries
article
free
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
api-ms-win-crt-heap-l1-1-0.dll
DLLExport
free
C++
memory blocks, deallocating
free function
74ded9cf-1863-432e-9306-327a42080bb8
14
corob-msft
corob
ghogen

free

Deallocates or frees a memory block.

Syntax

void free(   
   void *memblock   
);  

Parameters

memblock
Previously allocated memory block to be freed.

Remarks

The free function deallocates a memory block (memblock) that was previously allocated by a call to calloc, malloc, or realloc. The number of freed bytes is equivalent to the number of bytes requested when the block was allocated (or reallocated, in the case of realloc). If memblock is NULL, the pointer is ignored and free immediately returns. Attempting to free an invalid pointer (a pointer to a memory block that was not allocated by calloc, malloc, or realloc) may affect subsequent allocation requests and cause errors.

If an error occurs in freeing the memory, errno is set with information from the operating system on the nature of the failure. For more information, see errno, _doserrno, _sys_errlist, and _sys_nerr.

After a memory block has been freed, _heapmin minimizes the amount of free memory on the heap by coalescing the unused regions and releasing them back to the operating system. Freed memory that is not released to the operating system is restored to the free pool and is available for allocation again.

When the application is linked with a debug version of the C run-time libraries, free resolves to _free_dbg. For more information about how the heap is managed during the debugging process, see The CRT Debug Heap.

free is marked __declspec(noalias), meaning that the function is guaranteed not to modify global variables. For more information, see noalias.

To free memory allocated with _malloca, use _freea.

Requirements

Function Required header
free <stdlib.h> and <malloc.h>

For additional compatibility information, see Compatibility in the Introduction.

Example

See the example for malloc.

See Also

Memory Allocation
_alloca
calloc
malloc
realloc
_free_dbg
_heapmin
_freea