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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:45:18+00:00 2026-05-15T09:45:18+00:00

Hello another stupid question regarding leaks and also NSURLConnection. How do i release it?

  • 0

Hello another stupid question regarding leaks and also NSURLConnection. How do i release it? Is it enough if i release in the following 2 methods?

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

Because in instruments it shows me the line where I alloc my connection as the source of leaking.

(EDIT1: OK I don’t get it. After the following code my urlConnection has a retain count of 2. WTF?)

NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest: urlRequest delegate: self];

This is the line that instruments points me to.

EDIT2: here is some code:

I create the connection here

- (void) makeRequest
{

    //NSString *urlEncodedAddress = [self.company.street stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];

    NSString *urlString = [[NSString alloc] initWithFormat:
                               @"http://maps.google.com/maps/api/geocode/xml?latlng=%f,%f&sensor=false",
                               bestEffort.coordinate.latitude,bestEffort.coordinate.longitude];
    debugLog(@"%@",urlString);

    NSURL *url = [[NSURL alloc] initWithString: urlString];
    [urlString release];
    NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL: url];
    [url release];
    NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest: urlRequest delegate: self];
  debugLog(@"connection created %@ rc %i", urlConnection, urlConnection.retainCount);
    [urlRequest release];
    connection = urlConnection;
}

I release it here

-(void)connection:(NSURLConnection *)_connection didFailWithError:(NSError *)error
{
    debugLog(@"ERROR with the connection: %@", error.localizedDescription);
    //[activityIndicator setHidden:YES];

  debugLog(@"connection will be released or else %@ %i", _connection, [_connection retainCount]);

    [connection release];
    connection = nil;
    [webData release];
    webData = nil;

    if (!cancel)
        [delegate rgc_failedWithError: self : error];

    isWorking = FALSE;

}

Or here

-(void)connectionDidFinishLoading:(NSURLConnection *)_connection
{
  debugLog(@"connection will be released (or else) %@ %i", _connection, [_connection retainCount]);

    [connection release];
    connection = nil;

    debugLog(@"DONE. Received Bytes: %d", [webData length]);
    //NSString *theXML = [[NSString alloc] initWithBytes: [webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
    //debugLog(@"%@",theXML);
    //[theXML release];
        .....
        .....
}

EDIT3: Problem solved by not caring whether it’s leaking or not! Simple!

  • 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-15T09:45:19+00:00Added an answer on May 15, 2026 at 9:45 am

    You’re correct to release it in the delegate methods, however the analysis tools like instruments and the clang analyser aren’t clever enough to deal with that and report a false positive. I’d be inclined to file a bug with apple, it will certainly be a duplicate but will tell them that more developers are finding this annoying.

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

Sidebar

Related Questions

hello i need to do the following: move a node from jstree to another
I have the following data: A post called Hello has categories greet Another post
Consider the following messages table: _date message ------------------------- 2012-02-22 hello 2012-02-22 another msg! 2012-03-05
Hello everyone it is me again with another question. The booking system located here
Hello i have a question about servlet calling another servlet I have a main
hello all im back with another question on my project. i keep getting stuck
hello I have a NSMutableArray iconlocarr . I also have another array containing dictionary
Hello good people of Stack Overflow, I have come with yet another question for
i have written the following code to copy a string hello world to another
Hello people from StackOverflow! I come to you with yet another question. :) As

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.