C 我不得不说;“免费”;rootValue,但是在返回它之前我应该怎么做呢?
我不能只返回rootValue,因为我需要使用C 我不得不说;“免费”;rootValue,但是在返回它之前我应该怎么做呢?,c,C,我不能只返回rootValue,因为我需要使用 JSON_Value* createJSONObject() { JSON_Value *rootValue = json_value_init_object(); JSON_Object *rootObject = json_value_get_object(rootValue); return rootValue; } 否则,内存将保持打开状态。我该怎么做?您不能返回您释放的任何内容。(好吧,你可以这样做,但是不行。)
JSON_Value* createJSONObject()
{
JSON_Value *rootValue = json_value_init_object();
JSON_Object *rootObject = json_value_get_object(rootValue);
return rootValue;
}
否则,内存将保持打开状态。我该怎么做?您不能返回您释放的任何内容。(好吧,你可以这样做,但是不行。) 在函数契约中声明,调用方必须在使用后释放返回值
json_value_free(rootValue);