johnezang/JSONKit — Issue #53: Memory leak in jk_cachedObjects
Author: mast
Created: 2011-10-20 16:49:43+00:00
State: open

I observe memory leaks, which may be quite significant for me.

I do the following code in my view controller:

JSONDecoder *json = [JSONDecoder decoder];

if (![data isKindOfClass:[NSData class]])
{
// Error occurred
return;
}

// Ok, data is received, parse it
NSDictionary *parsed = [json objectWithData:data];

As soon as I move to another controller I get:

Leaked Object	#	Address	Size	Responsible Library	Responsible Frame
NSCFString,5	< multiple >	144 Bytes	App	jk_cachedObjects
NSCFString,1	0x18ac40	32 Bytes	App	jk_cachedObjects
NSCFString,1	0x18b340	16 Bytes	App	jk_cachedObjects
NSCFString,1	0x18b7e0	32 Bytes	App	jk_cachedObjects
NSCFString,1	0x18bc90	32 Bytes	App	jk_cachedObjects
NSCFString,1	0x18cb60	32 Bytes	App	jk_cachedObjects

id	Address	Category	Event Type	RefCt	Timestamp	Size	Responsible Library	Responsible Caller
0	0x18ac40	CFString (immutable)	Malloc	1	00:15.891.265	32	App	jk_cachedObjects
1	0x18ac40	CFString (immutable)	CFRetain	2	00:15.891.302	0	App	jk_cachedObjects
2	0x18ac40	CFString (immutable)	CFRetain	3	00:15.903.345	0	Foundation	-[NSCFString retain]
3	0x18ac40	CFString (immutable)	CFRelease	2	00:15.973.275	0	App	-[JKDictionary dealloc]
4	0x18ac40	CFString (immutable)	CFRelease	1	00:15.980.459	0	App	-[JSONDecoder clearCache]

I shouldn't do the following, isn't? At least it's not obvious.

[json release];
[parsed release];

I parse lots of data (at least once each 5 minutes), so such leak is quite critical for me.
Can you be so kind as to dig into this? May be it's just my stupid fault, but it doesn't look like that for me right now.