### _uheapmin -- Release Unused Memory in User Heap

Format

>     #include <umalloc.h>
>     int _uheapmin(Heap_t heap);

Language Level: Extension
_uheapmin returns all unused memory blocks from the heap you specify to the operating system.

_uheapmin works just like _heapmin, except that you specify the heap to use; _heapmin always uses the default heap. A debug version of this function, _debug_uheapmin, is also provided.

To return the memory, _uheapmin calls the release_fn you supplied when you created the heap with _ucreate. If you did not supply a release_fn, _uheapmin has no effect and simply returns 0.

Return Value
If successful, _uheapmin returns 0. A nonzero return value indicates failure. Passing _uheapmin a heap that is not valid has undefined results.

Example
This example creates a heap and then allocates and frees a large block of memory from it. It then calls _uheapmin to return free blocks of memory to the system.

    #include <stdlib.h>
    #include <stdio.h>
    #include <umalloc.h>
    #include <string.h>

    int main(void)
    {
       Heap_t  myheap;
       char    *ptr;

       /* Use default heap as user heap */
       myheap = _udefault(NULL);

       /* Allocate a large object */
       if (NULL == (ptr = (char*)_umalloc(myheap, 60000))) {
          puts("Cannot allocate memory from user heap.");
          exit(EXIT_FAILURE);
       }
       memset(ptr, 'x', 60000);
       free(ptr);

       /* _uheapmin will attempt to return the freed object to the system */
       if (0 != _uheapmin(myheap)) {
          puts("_uheapmin failed.");
          exit(EXIT_FAILURE);
       }
       return 0;
    }

Managing Memory with Multiple Heaps
Memory Management

_heapmin -- Release Unused Memory From Default Heap
_debug_uheapmin -- Release Unused Memory in User Heap
_ucreate -- Create a Memory Heap
_theapmin -- Release Unused Tiled Memory
<umalloc.h>