Code Monkey home page Code Monkey logo

Comments (6)

vguerci avatar vguerci commented on June 22, 2024

That was a bad code + misunderstanding of Instruments reports.

Bad me.

from jsonkit.

droppsm avatar droppsm commented on June 22, 2024

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

from jsonkit.

vguerci avatar vguerci commented on June 22, 2024

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

from jsonkit.

droppsm avatar droppsm commented on June 22, 2024

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.

from jsonkit.

johnezang avatar johnezang commented on June 22, 2024

@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.

from jsonkit.

johnezang avatar johnezang commented on June 22, 2024

... 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.

from jsonkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.