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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:52:27+00:00 2026-06-15T17:52:27+00:00

I’m new to Objective-c. I wrote a few lines of code to access a

  • 0

I’m new to Objective-c. I wrote a few lines of code to access a web-service asynchronously and then process the results. Could you please explain how the ARC works when an asynchronous method takes a delegate (protocol) as an argument?

For example I’m invoking the web-service by using a local NSURLConnection in a method:

-(void) invokeSomeWebServiceMethod {
   MyDelegate *const theDelegate = ...;
   NSURL *const url = ...;
   NSURLRequest *const request = ...;
   [NSURLConnection connectionWithReuqest: request delegate:theDelegate]; 
}

I wasn’t sure this approach would work, since the implicit NSURLConnection which is returned as a result of the connectionWithRequest message should be marked for clean-up, because neither the calling method nor the delegate has a reference to it. But it works!

So:

  1. How does the runtime know not to prematurely wipe-out the
    NSURLConnection that’s doing work?
  2. List item Should I be releasing/closing the connection in my delegate once
    connectionDidFinishLoading message is received?
  3. Does it make more sense for the delegate to declare the invokeSomeWebServiceMethod and pass self as part of the connectionWithRequest message? Then the creation of the NSURLConnection is encapsulated inside the delegate.

Thanks

  • 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-06-15T17:52:28+00:00Added an answer on June 15, 2026 at 5:52 pm
    1. While the connection is downloading, it retains itself.

    2. If you have any strong references to the connection, you should set them to nil once you’re done with the connection object.

    3. To answer this question, I need more information about what MyDelegate really is and what object currently hosts invokeSomeWebServiceMethod.

    You can look at the retains and releases yourself by running your app under the Allocations instrument with “Record reference counts” enabled and “Only track active allocations” disabled:

    allocations instrument options

    Then, after running your program under Instruments, you can type “NSURLConnection” into the search bar and drill down by clicking the little white arrows in gray circles to see the trace for a single object:

    instruments history for one NSURLConnection

    You can see in that screen shot (right-click and open in a new tab for full size) that -[NSURLConnectionInternal initWithInfo:] retains the connection (line 1). That retain is balanced by a release later after the connection has finished sending all of its delegate messages.

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

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms

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.