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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:02:59+00:00 2026-05-20T11:02:59+00:00

first look at these code: NSURL *url = [[NSURL alloc] initWithString:@lasdhfkjasf]; NSURLRequest *request =

  • 0

first look at these code:

NSURL *url = [[NSURL alloc] initWithString:@"lasdhfkjasf"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSURLConnection *_conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSLog(@"aaaaaaaaa  %d", [_conn retainCount]);
[url release];
[request release];
[_conn release];

turns out it prints “aaaaaaaaaaaaa 2”,shouldn’t it be 1?Or there are some kind of exception out there.Then I change it :

NSURL *url = [[NSURL alloc] initWithString:@"lasdhfkjasf"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSURLConnection *_conn = [[NSURLConnection alloc] init];
NSLog(@"aaaaaaaaa  %d", [_conn retainCount]);
[url release];
[request release];
[_conn release];

I don’t know happen in the initWithRequest:delegate: method,has anybody know about it?

  • 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-20T11:03:00+00:00Added an answer on May 20, 2026 at 11:03 am

    Everything is absolutely OK here: NSURLConnection must retain itself to be sure that it can deliver data to the delegate (and to do that it must not be deallocated). If there is no delegate, then nobody listens to that connection and there is no reason to perform anything, so it doesn’t retain itself. Connection then releases itself after:

    -(void) connectionDidFinishLoading:(NSURLConnection*) connection
    

    OR

    -(void) connection:(NSURLConnection*) connection didFailWithError:(NSError*) error
    

    From your example:

    . . .
    NSURLConnection *_conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    . . .
    [_conn release];
    

    if retainCount was 1, then after [_conn release] the object would be deallocated immediately and there would be no loading at all.

    To all of you, who says that retainCount works incorrectly: you just don’t know how it works. As for NSString ‘oddity’: this is not oddity, this is just performance optimization. 2147483647 retain count means that object is constant in memory (and is deleted when app terminates). This is done when the value is known during compilation:

    NSString* str = @"12345"; //has 2147483647 retain count.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please have a look at this code: Card *first = [[Card alloc] initWithFace:@Ace andSuit:@Hearts];
Please look at these 3 code blocks first. Code Block 1: var t1 =
First look at this url: https://stackoverflow.com/questions/tagged/xoxoxo/ This directory does not exists but somehow stackoverflow
How to make the first matrix look like the latter? The code of the
First take a look at my code: <ListBox ItemsSource={Binding} SelectionMode=Multiple ItemTemplate={StaticResource ContactTemplate}> <ListBox.ContextMenu> <ContextMenu>
look at these two codes First: Slide _Slide = DataContext.Slides.SingleOrDefault(rec => rec.Id == _SlideObj.Id);
When you take your first look at an Oracle database, one of the first
I have tried this example http://www.bennadel.com/blog/1056-ColdFusion-CFPOP-My-First-Look.htm , but it retrieve emails from POP server.
OK, first for context look at the Windows desktop; You can take items (folders,
First of all I did gave a look at this one. But I didn't

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.