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 6681441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:35:26+00:00 2026-05-26T04:35:26+00:00

so i’m using AFNetworking for doing asynchronous requests with web-services. AFJSONRequestOperation *operation = [AFJSONRequestOperation

  • 0

so i’m using AFNetworking for doing asynchronous requests with web-services.

AFJSONRequestOperation *operation = [AFJSONRequestOperation operationWithRequest:request success:^(id JSON)
    {
        [self doSomeStuff];

    } failure:^(NSHTTPURLResponse *response, NSError *error)
    {
        XLog("%@", error);
    }];

    NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
    [queue addOperation:operation];

now what happens when the “self” object is dealloced before the request finished is, that my application chrashes on [self doSomeStuff]; of course.

is there a way to cancel this block-request when deallocating my object?

  • 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-26T04:35:27+00:00Added an answer on May 26, 2026 at 4:35 am

    I did some sample code and the result can interest to you.

    I created a class that creates a request just like yours:

    @implementation Aftest
    @synthesize name = _name;
    - (void) doSomeStuff
    {
        NSLog(@"Got here %@", self.name);
    }
    
    - (void)startDownload
    {   
          self.name = [NSString stringWithFormat:@"name"];
          NSURL *requestURL = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=twitterapi&count=2"];
          NSURLRequest *request = [NSURLRequest requestWithURL:requestURL];
          AFJSONRequestOperation *operation = [AFJSONRequestOperation operationWithRequest:request success:^(id JSON)
          {
               [self doSomeStuff];
    
          } failure:^(NSHTTPURLResponse *response, NSError *error)
          {
               NSLog(@"%@", [error localizedDescription]);
          }];
    
          NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
          [queue addOperation:operation];
    }
    @end
    

    And called this with:

    Aftest *af = [[Aftest alloc] init];
    NSLog(@"1 - retain count %d", [af retainCount] );
    [af startDownload];
    NSLog(@"2 - retain count %d", [af retainCount] );
    [af release];
    NSLog(@"3 - retain count %d", [af retainCount] );
    

    The result that I got was:

    2011-10-09 09:28:41.415 aftes[6154:f203] 1 - retain count 1
    2011-10-09 09:28:41.418 aftes[6154:f203] 2 - retain count 2
    2011-10-09 09:28:41.419 aftes[6154:f203] 3 - retain count 1
    2011-10-09 09:28:43.361 aftes[6154:f203] Got here name
    

    Your object should be retained when passed inside the block. It should be avoiding these crashes.

    Either way, as Micheal answered, it should be possible to call cancel as long as you have access to the operation object.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to

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.