I was wondering if the call to operator delete
is synchronous or not. In other words, if I do:
delete p;
Does the C++ Standard guarantee that only after this call finishes execution the memory is freed? Or is the call asynchronous and simply schedules a task for OS to free this memory as soon as it decides that it is the best time to do so?
If the first case is the valid one, then does it mean that we have to implement our own asynchronous deleter facility? I'm asking because I'd say that most of the time we (programmers) don't care when the memory is freed exactly, and therefore we don't want our code to freeze and wait for this (most likely expensive?) system call to finish, but rather schedule a task for deletion and immediately continue the execution. Does C++ provide any standard facility (maybe through standard library?) to do this without reinventing the wheel?
new
anddelete
operator. It is very common when you have many small objects.std::unique_ptr
and use a custom deleter.