Clay destroy and re-Initialize
Author: tuketCreated Aug 30, 2026Updated Aug 30, 2026
I see there is Clay_Initialize but there isn't an equivalent "destroy" function.
I guess it's just a matter of deleting the memory you passed to Clay_CreateArenaWithCapacityAndMemory yourself.
I did that, but when I call Clay_Initialize with new memory it will crash.
Looks like Clay_Initialize uses the old context to copy some parameters:
Clay_Context *oldContext = Clay_GetCurrentContext();
*context = CLAY__INIT(Clay_Context) {
.maxElementCount = oldContext ? oldContext->maxElementCount : Clay__defaultMaxElementCount,
.maxMeasureTextCacheWordCount = oldContext ? oldContext->maxMeasureTextCacheWordCount : Clay__defaultMaxMeasureTextWordCacheCount,
.errorHandler = errorHandler.errorHandlerFunction ? errorHandler : CLAY__INIT(Clay_ErrorHandler) { Clay__ErrorHandlerFunctionDefault, 0 },
.layoutDimensions = layoutDimensions,
.internalArena = arena,
};I guess I can just Clay_SetCurrentContext(NULL) when I delete the arena's memory. Is that the intended usage?
I'm also curious, why does it try to replicate those parameters from the old context?
Source: nicbarker/clay