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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:01:02+00:00 2026-05-16T23:01:02+00:00

Calling instance method cancel on an NSURLConnection most often don’t cancel the connection at

  • 0

Calling instance method cancel on an NSURLConnection most often don’t cancel the connection at all.

I’m performing an asynchronous NSURLConnection in an NSOperation. If the operation is cancelled, the connection is stopped by calling cancel on NSURLConnection and then setting the connection to nil.

Is there a way to cancel the connection immediatly? Most often it continues running in the background until the request is finished even though both the connection is canceled and set to nil. The NSOperation subclass is dealloced after the connection is canceled, where the connection is released. Even after that, the asynchronous connection continues running!

Is there another way to cancel it? Or can the thread its running on be canceled?

Here is a code snippet from my NSOperation subclass main method:

      // Create and start asynchronous connection
      self.connection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
      [request release];

      while(!isFinished) {
          if(self.isCancelled) {
             [self.connection cancel];
             self.connection = nil; 
             [self uploadCanceledDelegate];
             return;
          }

          // Special sleep because callbacks are executed on same thread as this loop
          [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
      }

NOTE: This behaviour only occur when WiFi is enabled. With 3G/Edge/GPRS it works fine

  • 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-16T23:01:03+00:00Added an answer on May 16, 2026 at 11:01 pm

    This might be a problem with Apple’s documentation.

    It’s possible that the connection is currently waiting in a blocked thread, and there’s nothing the OS will do immediately while that thread is blocked. The thread won’t really be canceled until it becomes unblocked at some later point in time. Therefore you should not release any objects handling those cancelled connections until some unknown point in the future when the socket the thread is waiting on times out or is closed.

    If you are experiencing leaks or crashes, you might try moving the “cancelled” operation objects to another queue of stuff waiting to be released a few seconds or maybe even minutes later.

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

Sidebar

Related Questions

In Python, is there a way to bind an unbound method without calling it?
Can you create a delegate of an instance method without specifying the instance at
I am using the actionSheet variable passed by actionSheet:didDismissWithButtonIndex: to compare the calling actionSheet
I am running into a problem where my CRUD operations on an entity sourced
I've got the following code: void ReferenceManager_DoWork(object sender, DoWorkEventArgs e) { try { //
Foo = Class.new Foo.instance_eval do def instance_bar instance_bar end end puts Foo.instance_bar #=> instance_bar
There are several different ways I can initialize complex objects (with injected dependencies and
I have an application I am attempting to convert from a flex 3 air
I am trying to do the following in a Ruby on Rails project: class
I am writing a Bytecode instrumenter. Right now, I am trying to find out

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.