D Language Scope guards Place allocation and cleanup code next to each other


Example

Scope guards allow executing statements at certain conditions if the current block is left.

import core.stdc.stdlib;

void main() {
    int* p = cast(int*)malloc(int.sizeof);
    scope(exit) free(p);
}