最近有读写json文件的需求,在网上找到一段代码
来源:[C++]使用Jansson生成与解析json字符串
自己用了这个json_delete函数,发现通不过编译,网上也找不到相关的说明。
查阅官方API参考,发现找不到这个函数。
查看源码,发现有注释
/* do not call json_delete directly */
void json_delete(json_t *json);
源码中告诉我们,不要直接调用这个函数。
为什么呢?
终于在github找到了答案。
原回答:
Don’t call json_delete, it’s done automatically when refcount drops to 0. The memory contents are still intact, but accessing the freed memory is an error nevertheless.
大概意思是不要调用json_delete,当引用计数到0时,会自动调用json_delete,问题解决。