MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / RM_RetainString

Function RM_RetainString

src/module.cpp:1293–1306  ·  view source on GitHub ↗

Every call to this function, will make the string 'str' requiring * an additional call to RedisModule_FreeString() in order to really * free the string. Note that the automatic freeing of the string obtained * enabling modules automatic memory management counts for one * RedisModule_FreeString() call (it is just executed automatically). * * Normally you want to call this function when, at th

Source from the content-addressed store, hash-verified

1291 *
1292 * It is possible to call this function with a NULL context. */
1293void RM_RetainString(RedisModuleCtx *ctx, RedisModuleString *str) {
1294 if (ctx == NULL || !autoMemoryFreed(ctx,REDISMODULE_AM_STRING,str)) {
1295 /* Increment the string reference counting only if we can't
1296 * just remove the object from the list of objects that should
1297 * be reclaimed. Why we do that, instead of just incrementing
1298 * the refcount in any case, and let the automatic FreeString()
1299 * call at the end to bring the refcount back at the desired
1300 * value? Because this way we ensure that the object refcount
1301 * value is 1 (instead of going to 2 to be dropped later to 1)
1302 * after the call to this function. This is needed for functions
1303 * like RedisModule_StringAppendBuffer() to work. */
1304 incrRefCount(str);
1305 }
1306}
1307
1308/**
1309* This function can be used instead of RedisModule_RetainString().

Callers

nothing calls this directly

Calls 2

autoMemoryFreedFunction · 0.85
incrRefCountFunction · 0.85

Tested by

no test coverage detected