Releases or decommits a region of pages within the virtual address space of the calling process.
BOOL VirtualFree(
LPVOID lpAddress,
SIZE_T dwSize,
DWORD dwFreeType
)
lpAddress
Type: LPVOID
[in] A pointer to the base address of the region of pages to be freed. If the dwFreeType parameter is MEM_RELEASE, this parameter must be the base address returned by the VirtualAlloc function when the region of pages is reserved.
dwSize
Type: SIZE_T
[in] The size of the region of memory to be freed, in bytes. If the dwFreeType parameter is MEM_RELEASE, this parameter must be 0 (zero). The function frees the entire region that is reserved in the initial allocation call to VirtualAlloc.
If the dwFreeType parameter is MEM_DECOMMIT, the function decommits all memory pages that contain one or more bytes in the range from the lpAddress parameter to (lpAddress+dwSize). This means, for example, that a 2-byte region of memory that straddles a page boundary causes both pages to be decommitted. If lpAddress is the base address returned by VirtualAlloc and dwSize is 0 (zero), the function decommits the entire region that is allocated by VirtualAlloc. After that, the entire region is in the reserved state.
dwFreeType
Type: DWORD
[in] The type of free operation. This parameter can be one of the following values.
| Value | Meaning |
|---|---|
| MEM_DECOMMIT 0x4000 | Decommits the specified region of committed pages. After the operation, the pages are in the reserved state. The function does not fail if you attempt to decommit an uncommitted page. This means that you can decommit a range of pages without first determining the current commitment state. Do not use this value with MEM_RELEASE. |
| MEM_RELEASE 0x8000 | Releases the specified region of pages. After this operation, the pages are in the free state. If you specify this value, dwSize must be 0 (zero), and lpAddress must point to the base address returned by the VirtualAlloc function when the region is reserved. The function fails if either of these conditions is not met. If any pages in the region are committed currently, the function first decommits, and then releases them. The function does not fail if you attempt to release pages that are in different states, some reserved and some committed. This means that you can release a range of pages without first determining the current commitment state. Do not use this value with MEM_DECOMMIT. |
Type: BOOL
If the function succeeds, the return value is true.
If the function fails, the return value is false.
Header: Declared in memoryapi.h.