Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7432597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:28:59+00:00 2026-05-29T09:28:59+00:00

I have a problem with my code that for the life of me I

  • 0

I have a problem with my code that for the life of me I can’t figure out, not even with all previous threads here on SO.
I’m pulling data from a JSON source and putting it in an NSDictionary as stated in tutorials and on SO. When profiling the app, I notice a memory leak caused by this NSDictionary but releasing it at the end of this function crashes the app. Any suggestions?
(By the way: I’m new to Obj-C and programming in general, so this code is mostly cherrypicked from various sources.)

- (void)fetchedData:(NSData *)responseData {
    //parse JSON for empty return
    if([responseData length] != 0){

        NSError* error = nil;
        //Convert JSON data to Obj-C
        NSDictionary* allShotData = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

        NSString *player = [[allShotData objectForKey:@"player"] objectForKey:@"name"];
        NSString *shotDribbblePage = [allShotData objectForKey:@"url"];

        NSString *shotTitle = [allShotData objectForKey:@"title"];
        NSURL *imageURL = [NSURL URLWithString:[allShotData objectForKey:@"image_url"]];
        shotPageURL = [shotDribbblePage retain];


        //***********************
        //  Setup a-sync loading of shot
        //***********************

        NSOperationQueue *queue = [NSOperationQueue new];
        NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadImage:) object:imageURL];   
        [queue addOperation:operation]; 
        [operation release];
        [queue release];
    }
    else{
        airballCount++;
        if (airballCount <= 20) {
            [self getDribbbleData];
        }
        else{
            NSLog(@"Too many airballs. Bailing out");
            [self showNoConnectionModal];
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:29:00+00:00Added an answer on May 29, 2026 at 9:29 am

    Here:

    shotPageURL = [shotDribbblePage retain];
    

    you should probably use the accessor:

    self.shotPageURL = shotDribbblePage;
    

    I should really emphasize that you should use your accessors everywhere since they do your ref counting for you (exception: not in initializers and dealloc). As beryllium also notes, you could do your ref counting manually if there is no accessor. That takes the basic form:

    [shotPageURL release];
    shotPageURL = [shotDribbblePage retain];
    

    If it’s the contents of the returned dictionary that are leaking, then it’s how you have used/referenced the contents when read (over-retain).

    If you’re using your class in a concurrent context, then you will usually need a lock.

    If you’re loading a UIImage or otherwise interacting with UIKit objects from a secondary thread — that’s not good.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a peculiar problem here and I can't by my life figure out
Hi I have a code example available here: http://jsbin.com/oxoweh My problem is that I
I can't for the life of me figure why this code is not working.
I have a code problem which stems from the fact that I am using
I have some code that I'd like to run on a page. My problem
I recently have a problem that my java code works perfectly ok on my
I'm having a strange problem which I cannot figure out for the life of
Ok I have searched all over and I can't not seem to find the
I've gotten stung by a bug that I just can't figure out how to
I'm having a very weird problem that for the life of me I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.