Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leaks or Instruments bad use/misunderstanding? #14

Closed
vguerci opened this issue Apr 6, 2011 · 6 comments
Closed

Memory leaks or Instruments bad use/misunderstanding? #14

vguerci opened this issue Apr 6, 2011 · 6 comments
Assignees

Comments

@vguerci
Copy link

vguerci commented Apr 6, 2011

Hi,

First of all, thanks a lot for your great work!

Could you please look at that SO question and tell us if those are leaks from JSONKit we are seeing or we are just noobs? :)

Feel free to contact me for more informations.

Vincent.

@vguerci
Copy link
Author

vguerci commented Apr 7, 2011

That was a bad code + misunderstanding of Instruments reports.

Bad me.

@vguerci vguerci closed this as completed Apr 7, 2011
@ghost ghost assigned johnezang May 21, 2011
@droppsm
Copy link

droppsm commented Aug 29, 2011

I'm experiencing the same issue in your SO post - what is the solution? Or are these cached items not a problem?

@vguerci
Copy link
Author

vguerci commented Aug 29, 2011

The solution is to track and fix the memory leak, 99,94% chances that comes from your code...

@droppsm
Copy link

droppsm commented Sep 12, 2011

I don't doubt that I'm doing something wrong, I just can't seem to figure out what it is. Are there JSONKit examples somewhere? Was the issue that you had a matter of releasing the decoder object? This is what I am doing...

JSONDecoder *decoder = [JSONDecoder decoder];   
NSDictionary *decodedResponse = [decoder objectWithData:responseData];

Are these autoreleased objects or do I need to handle releasing them? Confused...the leak report looks very similar to the one on Stack Overflow.

Thanks for any help.

@johnezang
Copy link
Owner

@droppsm,

JSONKit follows the standard Cocoa memory management conventions. In the example you provided, this means that the objects that are returned are autoreleased- you do not and should not send them a release message (unless, of course, you have sent them a retain message).

The most likely cause of your problems is that you have inadvertently sent the decodedResponse object a retain message without a corresponding release (or autorelease) message. If there is no reference to decodedResponse in your applications "live" memory, then there is no way for your application to even know that decodedResponse exists, and therefore it leaks. You will have to track down where the errant retain is, which can sometimes be tricky and non obvious.

@johnezang
Copy link
Owner

... as for "examples", your snippet of code is pretty much all there is to JSONKit. The only other major function is turning NSDictionary or NSArray objects in to JSON, which is usually done with:

JSONDecoder *decoder = [JSONDecoder decoder];   
NSDictionary *decodedResponse = [decoder objectWithData:responseData];

// Convert decodedResponse back in to JSON...

// UTF8 encoded bytes contained in a NSData object: (fastest)
NSData *convertedBackToJSONUTF8StringData = [decodedResponse JSONData];

// Exactly the same as above, but as a NSString object: (slower)
NSString *convertedBackToJSONString = [decodedResponse JSONString];

That's it. Which one you use depends on your needs- a NSString is easier to manipulate programmatically, and a NSData is usually the best choice when your sending data to a server.

That's all JSONKit does- it converts JSON in to NSDictionary or NSArray objects (via the code you posted), and converts NSDictionary or NSArray objects in to JSON. Everything else is bells and whistles for those that need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants