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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:34:14+00:00 2026-05-19T22:34:14+00:00

Apple guide is very specific about releasing connection object: it’s done in didFailWithError and

  • 0

Apple guide is very specific about releasing connection object: it’s done in didFailWithError and connectionDidFinishLoading.

Yet, when I do the same, I later get this in zombi-mode

*** -[NSURLConnection releaseDelegate]: message sent to deallocated instance 0x1001045b0

It seems, there’s some code in AppKit which releases connection for me.

I’d be happy to assume that Apple guide is wrong, but do not want to get some terrible memory leak or introduce some subtle incompatibility with older OSX versions or something like that.

Is it safe to ignore documentation in this case?

edit
Code creating request

  URLConnectionDelegate *delegate = [[URLConnectionDelegate alloc] initWithSuccessHandler:^(NSData *response) {
      ...
  }];
  [NSURLConnection connectionWithRequest:request delegate:delegate];  

  // I do not release delegate when testing for this issue, not sure whether I should in general

Delegate class itself

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
  successHandler(receivedData);

  [receivedData release];
  Block_release(successHandler);

  // do we really need this????????
  [connection release];
}
  • 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-19T22:34:15+00:00Added an answer on May 19, 2026 at 10:34 pm

    Since you’ve created your connection with

    [NSURLConnection connectionWithRequest:request delegate:delegate]; 
    

    you don’t own that connection object, hence you shouldn’t release it.

    That being said, I wouldn’t recommend it. If you don’t own an object, you have no guarantee that it will outlive autorelease pool drain cycles, i.e., it could be the case that your connection object is (auto)released before it’s finished loading. Instead, create a retain declared property to hold the connection:

    @property (retain) NSURLConnection *connection;
    

    assign your connection object to the declared property:

    self.connection = [NSURLConnection connectionWithRequest:request
        delegate:delegate]; 
    

    and, when the connection finishes loading or fails, release it by assigning nil to the declared property:

    self.connection = nil;
    

    As for your delegate, if it only needs to exist whilst the connection is loading, you can autorelease it since the connection retains the delegate:

    URLConnectionDelegate *delegate = [[[URLConnectionDelegate alloc]
        initWithSuccessHandler:^(NSData *response) {
        // …
    }] autorelease];
    
    self.connection = [NSURLConnection connectionWithRequest:request
        delegate:delegate]; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While most apple documents are very well written, I think ' Event Handling Guide
I'm using this very simple code from the Apple Guide: NSMutableData *receivedData; // Create
As per the Apple guide: As a result of the presented notification, the user
Iphone accelerometer provides user acceleration and gravity reading? It's clear from the apple guide
i am studying apple obj-c guide and i am having problem understanding class types,
On page 7 of Apple's Local and Push Notification Programming Guide there is a
Apple really had bad documentation about how the provider connects and communicates to their
On the Apple guide, there is a step before building the AppStore version: Open
I am trying to use a snippet of code from a Apple programming guide,
I have MAC OS 10.6 (Snow Leopard) and according to Apple's guide on HTTP

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.