bmybbs / PrototypeDevManagement

1 stars 1 forks source link

json-c 内存泄漏测试 #52

Open IronBlood opened 10 years ago

IronBlood commented 10 years ago

@Liu-Ameng

json-c 的 API 中如是写到:

struct json_object* json_object_new_object(void)

Create a new empty object with a reference count of 1. The caller of this object initially has sole ownership. Remember, when using json_object_object_add or json_object_array_put_idx, ownership will transfer to the object/array. Call json_object_get if you want to maintain shared ownership or also add this object as a child of multiple objects or arrays. Any ownerships you acquired but did not transfer must be released through json_object_put.

是不是意味着我们在代码中每使用一次 json_object_get 函数,就应当伴随着 json_object_put?用一段代码测试看看?

pffang commented 9 years ago

不是,仅需put全部new出来的对象。包括json_tokener_parse和json_object_from_file。从其他对象get出来的无需put。