Frees the specified local memory object and invalidates its handle.
Note The local functions are slower than other memory management functions and do not provide as many features. Therefore, new applications should use the
heap functions.
Syntax
HLOCAL WINAPI LocalFree(
__in HLOCAL hMem
);
Parameters
- hMem [in]
-
A handle to the local memory object. This handle is returned by either the
LocalAlloc or
LocalReAlloc function. It is not safe to free memory allocated with GlobalAlloc.
Return Value
If the function succeeds, the return value is NULL.
If the function fails, the return value is equal to a handle to the local memory object. To get extended error information, call
GetLastError.
Remarks
If the process tries to examine or modify the memory after it has been freed, heap corruption may occur or an access violation exception (EXCEPTION_ACCESS_VIOLATION) may be generated.
If the hMem parameter is NULL,
LocalFree ignores the parameter and returns NULL.
The
LocalFree function will free a locked memory object. A locked memory object has a lock count greater than zero. The
LocalLock function locks a local memory object and increments the lock count by one. The
LocalUnlock function unlocks it and decrements the lock count by one. To get the lock count of a local memory object, use the
LocalFlags function.
If an application is running under a debug version of the system,
LocalFree will issue a message that tells you that a locked object is being freed. If you are debugging the application,
LocalFree will enter a breakpoint just before freeing a locked object. This allows you to verify the intended behavior, then continue execution.
Example Code
For an example, see
LocalAlloc.
Requirements
| Client | Requires Windows Vista, Windows XP, or Windows 2000 Professional. |
| Server | Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server. |
| Header | Declared in Winbase.h; include Windows.h. |
| Library | Use Kernel32.lib. |
| DLL | Requires Kernel32.dll. |
See Also
Global and Local Functions
GlobalFree
LocalAlloc
LocalFlags
LocalLock
LocalReAlloc
LocalUnlock
Memory
Management Functions
Send comments about this topic to Microsoft
Build date: 6/12/2008