Next: , Previous: Memory Allocation, Up: Virtual Memory Interface


5.2 Memory Deallocation

— Function: kern_return_t vm_deallocate (vm_task_t target_task, vm_address_t address, vm_size_t size)

vm_deallocate relinquishes access to a region of a task's address space, causing further access to that memory to fail. This address range will be available for reallocation. address is the starting address, which will be rounded down to a page boundary. size is the number of bytes to deallocate, which will be rounded up to give a page boundary. Note, that because of the rounding to virtual page boundaries, more than size bytes may be deallocated. Use vm_page_size or vm_statistics to find out the current virtual page size.

This call may be used to deallocate memory that was passed to a task in a message (via out of line data). In that case, the rounding should cause no trouble, since the region of memory was allocated as a set of pages.

The vm_deallocate call affects only the task specified by the target_task. Other tasks which may have access to this memory may continue to reference it.

The function returns KERN_SUCCESS if the memory was successfully deallocated and KERN_INVALID_ADDRESS if an invalid or non-allocated address was specified.