Comments (4)
While there certainly exists the possibility that there is a memory leak inside JSONKit, at this point it has been in heavy use by a very large number of projects at this point, and most of the major bugs have been fixed.
Pragmatically, this means that the most likely cause of the memory leak is a bug in your code, not JSONKit. The leak information you're getting is the stack trace of where the allocation took place, which is not the same thing as where that allocation was leaked.
The most likely explanation is that you have over retained something that JSONKit has given you. Unfortunately, it is simply not possible for me to offer any more assistance than this generic advice. For now, I'm going to close this bug, but if you have additional information which clearly implicates JSONKit, feel free to re-open this bug or open a new one.
from jsonkit.
Thanks for your response. You was right and I found leak in my code in very non-obvious place. Sorry that I was complaining JSONKit!
from jsonkit.
I'm seeing the same leak. See this line of code in jk_cachedObjects:
https://github.com/johnezang/JSONKit/blob/master/JSONKit.m#L2038
switch(parseState->token.value.type) {
case JKValueTypeString: parsedAtom = (void *)CFStringCreateWithBytes(NULL, parseState->token.value.ptrRange.ptr, parseState->token.value.ptrRange.length, kCFStringEncodingUTF8, 0); break;
case JKValueTypeLongLong: parsedAtom = (void *)CFNumberCreate(NULL, kCFNumberLongLongType, &parseState->token.value.number.longLongValue); break;
case JKValueTypeUnsignedLongLong:
if(parseState->token.value.number.unsignedLongLongValue <= LLONG_MAX) { parsedAtom = (void *)CFNumberCreate(NULL, kCFNumberLongLongType, &parseState->token.value.number.unsignedLongLongValue); }
else { parsedAtom = (void *)parseState->objCImpCache.NSNumberInitWithUnsignedLongLong(parseState->objCImpCache.NSNumberAlloc(parseState->objCImpCache.NSNumberClass, @selector(alloc)), @selector(initWithUnsignedLongLong:), parseState->token.value.number.unsignedLongLongValue); }
break;
case JKValueTypeDouble: parsedAtom = (void *)CFNumberCreate(NULL, kCFNumberDoubleType, &parseState->token.value.number.doubleValue); break;
default: jk_error(parseState, @"Internal error: Unknown token value type. %@ line #%ld", [NSString stringWithUTF8String:__FILE__], (long)__LINE__); break;
}
if(JK_EXPECT_T(setBucket) && (JK_EXPECT_T(parsedAtom != NULL))) {
bucket = useableBucket;
if(JK_EXPECT_T((parseState->cache.items[bucket].object != NULL))) { CFRelease(parseState->cache.items[bucket].object); parseState->cache.items[bucket].object = NULL; }
if(JK_EXPECT_T((parseState->cache.items[bucket].bytes = (unsigned char *)reallocf(parseState->cache.items[bucket].bytes, parseState->token.value.ptrRange.length)) != NULL)) {
memcpy(parseState->cache.items[bucket].bytes, parseState->token.value.ptrRange.ptr, parseState->token.value.ptrRange.length);
parseState->cache.items[bucket].object = (void *)CFRetain(parsedAtom);
parseState->cache.items[bucket].hash = parseState->token.value.hash;
parseState->cache.items[bucket].cfHash = 0UL;
parseState->cache.items[bucket].size = parseState->token.value.ptrRange.length;
parseState->cache.items[bucket].type = parseState->token.value.type;
parseState->token.value.cacheItem = &parseState->cache.items[bucket];
parseState->cache.age[bucket] = JK_INIT_CACHE_AGE;
} else { // The realloc failed, so clear the appropriate fields.
parseState->cache.items[bucket].hash = 0UL;
parseState->cache.items[bucket].cfHash = 0UL;
parseState->cache.items[bucket].size = 0UL;
parseState->cache.items[bucket].type = 0UL;
}
}
return(parsedAtom);
parsedAtom
is created with a create
method, yielding an object with +1 retain count. CFRetain
is called on the parsedAtom yeilding a +2 retain count. The parsedAtom is not released.
Just making the change to remove the CFRetain
isn't sufficient; the parsedAtom is used elsewhere as a key in a JKObjectStack
, but not retained when it's added to that stack. I'm not sure what the proper solution is here, but I'm looking into it.
from jsonkit.
Please open a ticket with a concise test case that reproduces the memory leak.
At this point JSONKit is fairly mature and stable, and used in a lot of real world applications, none of which are experiencing memory leaks due to JSONKit.
To the best of my knowledge, every report of JSONKit leaking memory has turned out to be user error- the leak was caused by over retaining an object that was created by JSONKit. The memory leak tools can only show you the call stack that allocated the memory that was (eventually) leaked, NOT where the leak took place.
from jsonkit.
Related Issues (20)
- Any popular replacement for JSONKit? HOT 2
- BSD two-clause or three-clause license? HOT 2
- crash at JSONKit.m:2598:77 HOT 2
- Error in serializing NSNumber HOT 2
- Supporting gzip decompression
- Swift HOT 7
- can not use with xcode 7 HOT 4
- Xcode 7 Before is use JSONKit in Object but now not use JSONKit in Xcode 7 HOT 7
- crash with iOS9 Xcode7 HOT 5
- Should be #import <JSONKit/JSONKit.h> or <GCJSONKit/JSONKit.h>? HOT 1
- please ignore
- Crash when NSDictionary to String json format. HOT 1
- about convert json to NSDictioanry (error if json string contains double field) HOT 7
- JsonKit message JSONDataWithOptions crashes in macOS Sierra HOT 1
- JSONKit Installation error in X-code 7.3.1 iOS 9.3 HOT 1
- iOS TRAP_TRACE crash
- JSONKit semantic issue after updating the pod HOT 3
- Tagged pointer format changes in iOS 14 break JSONKit on ARM64 HOT 8
- @serkrapiv Not necessarily verboten, just that they must be escaped. The first paragraph of 2.5 Strings says: HOT 1
- Yea
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonkit.