> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PHEAP_TRACK_FREE_ROUTINE callback

> PHEAP_TRACK_FREE_ROUTINE callback

Represents a tracking callback function for heap de-allocation.

## Syntax

```cpp theme={null}
void PHEAP_TRACK_FREE_ROUTINE(  
         HANDLE Heap,  
         DWORD flags,  
         PVOID addr  
)  
```

### Parameters

*Heap*   \
Type: HANDLE

The handle to the heap from which the memory block was freed.

*flags*   \
Type: DWORD

The heap free options passed to [HeapFree](https://learn.microsoft.com/windows/desktop/api/heapapi/nf-heapapi-heapfree).

*addr*   \
Type: PVOID

The address of the memory block that was freed.

### Return value

Type: void

None.

## Remarks

This callback function can be implemented to track when a memory block previously allocated by the [HeapAlloc](https://learn.microsoft.com/windows/desktop/api/heapapi/nf-heapapi-heapalloc) or [HeapRealloc](https://learn.microsoft.com/windows/desktop/api/heapapi/nf-heapapi-heaprealloc) function is freed from a Win32 heap. Once implemented, you must register the implemented callback function by calling [XMemSetWin32HeapTrackingHooks](https://docs.xbox.com/reference/system/xmem/functions/xmemsetwin32heaptrackinghooks.md). The callback function is then invoked after `HeapFree` is called to free an allocated memory block from a Win32 heap. For more information about implementing this callback function, see the [Remarks](https://docs.xbox.com/reference/system/xmem/functions/xmemsetwin32heaptrackinghooks.md#remarksSection) section of `XMemSetWin32HeapTrackingHooks`.

## Requirements

**Header:** xmem.h

**Library:** xmem.lib

**Supported platforms:** XBOX One family consoles and XBOX Series consoles

## See also

[Diagnostics and memory tracking](https://docs.xbox.com/build/console-features/memory/system-memory-diagnostics.md)\
[XMemCreateWin32Heap](https://docs.xbox.com/reference/system/xmem/functions/xmemcreatewin32heap.md)\
[PHEAP\_TRACK\_ALLOC\_ROUTINE](https://docs.xbox.com/reference/system/xmem/functions/pheap_track_alloc_routine.md)\
[PHEAP\_TRACK\_REALLOC\_ROUTINE](https://docs.xbox.com/reference/system/xmem/functions/pheap_track_realloc_routine.md)\
[XMem](https://docs.xbox.com/reference/system/xmem/xmem_members.md)


## Related topics

- [XMemSetWin32HeapTrackingHooks](https://docs.xbox.com/reference/system/xmem/functions/xmemsetwin32heaptrackinghooks.md)
- [PHEAP_TRACK_ALLOC_ROUTINE callback](https://docs.xbox.com/reference/system/xmem/functions/pheap_track_alloc_routine.md)
- [PHEAP_TRACK_REALLOC_ROUTINE callback](https://docs.xbox.com/reference/system/xmem/functions/pheap_track_realloc_routine.md)
- [XMEMFREE_ROUTINE callback](https://docs.xbox.com/reference/system/xmem/functions/xmemfree_routine.md)
- [XMEMALLOC_ROUTINE callback](https://docs.xbox.com/reference/system/xmem/functions/xmemalloc_routine.md)
