This is an introduction to the custom memory management strategies you should be using to be writing "correct" code.

Introducing the custom allocator

The framework ships with a custom allocator(UImGui::Allocator) that should be used by your application. It contains all functions a standard C++ custom allocator should have.

This is needed to enable us to have plugins on Windows. It's good practice to use the custom allocator, however, it should be compatible with the normal standard allocator in most cases if you don't want to support plugins on Windows.

Caution

Make sure that you're using the correct wrappers on top of the regular standard library types. Standard library containers should not be used as is. More info can be found here.

C API

In the C API, you also have access to the following function as replacements for malloc and free:

  1. UImGui_Allocator_allocate
  2. UImGui_Allocator_deallocate

C API memory management

The C API provides you with 2 ways of managing your memory:

  1. Auto-deallocated - for objects that have relatively the same lifetime as the application
  2. Manually managed

In many interfaces, you can decide which deallocation strategy you want to use for a handle, by toggling the bManualDeallocation boolean argument that should be the last argument of the function that returns the handle. You can then call the respective free function for it.