簡體   English   中英

JSONKit是否會造成內存泄漏?

[英]Is JSONKit creating memory leaks?

我一直在我的應用程序中使用JSONKit ,但現在我已升級到Xcode 4.5.1並運行分析,Xcode報告了JSONKit代碼中可能的內存泄漏。

/Users/aleksa.topic/SVN/Apple/iTTChart/trunk/iTTChart/Other Sources/JSONKit.m:682:23: Memory is never released; potential leak of memory pointed to by 'array' /Users/aleksa.topic/SVN/Apple/iTTChart/trunk/iTTChart/Other Sources/JSONKit.m:682:23: Memory is never released; potential leak of memory pointed to by 'array' (並且它為字典提供了相同的潛在泄漏)。

有沒有人有這方面的經驗? 它真的會造成內存泄漏,還是只是Xcode的分析不夠好?

這在靜態分析儀中是誤報。 有一個錯誤報告試圖解決它。

看到這個鏈接 只需將標記為 - 的行替換為標記為+的行。

-    if((array = [array init]) == NULL) { return(NULL); }
+    if([array init] == NULL) { free(array); return(NULL); }

-    if(JK_EXPECT_F((array->objects = (id *)malloc(sizeof(id) * array->capacity)) == NULL)) { [array autorelease]; return(NULL); }
+    if(JK_EXPECT_F((array->objects = (id *)malloc(sizeof(id) * array->capacity)) == NULL)) { free(array); return(NULL); }

-    if((dictionary = [dictionary init]) == NULL) { return(NULL); }
+    if([dictionary init] == NULL) { free(dictionary);return(NULL); }

-    if(JK_EXPECT_F((dictionary->entry = (JKHashTableEntry *)calloc(1UL, sizeof(JKHashTableEntry) * dictionary->capacity)) == NULL)) { [dictionary autorelease]; return(NULL); }
+    if(JK_EXPECT_F((dictionary->entry = (JKHashTableEntry *)calloc(1UL, sizeof(JKHashTableEntry) * dictionary->capacity)) == NULL)) { free(dictionary); return(NULL); }

((array = [array init]) == NULL)替換為(dictionary == NULL)並使用free(array)函數代替[array autorelease]來修復它。 因為它是手動調整所以它也應該手動釋放。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM