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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:35:48+00:00 2026-05-20T20:35:48+00:00

I am starting my Objective-C journey with Cocoa Programming by Daniel H Setinberg. There

  • 0

I am starting my Objective-C journey with “Cocoa Programming” by Daniel H Setinberg. There is a bit that got me surprised related to the memory management. Actually I do find memory management in Objective C more complicated than in C, though I have not touched a “non garbage collected language” for a while so the old times of using malloc and its friends may be idealized in my memory :).

The bit that confused me is the following:

-(void) loadURLFromTextField{
  NSURL *url = [NSURL URLWithString:self.address.text];
  NSURLRequest *request = [NSURLRequest requestWithUrl:url];
  [self.webView loadRequest:request];
}

in second and third line I am allocating two objects so I assumed I need to release them somewhere. Yet the comment for this bit of code states:

“Note that we’re using class methods
to construct autoreleased instances of
the request and the URL. We don’t need
to release them ourselves.”

Could someone help me understand why those instances are autoreleased and how to get this from the SDK documentation. Is it a standard that all such class methods returining an object instance are actually autoreleased. Thanks for your help in advance!

  • 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-20T20:35:48+00:00Added an answer on May 20, 2026 at 8:35 pm

    You don’t have to release them as you don’t «own» them (you did not allocate them explicitly, nor retained them).

    Auto-released objects are placed on the current instance of the NSAutoreleasePool class, that will automatically send them a release message the next time the pool is drained, so usually at the end of the current run loop.

    That’s called convenience methods, that returns auto-released objects.

    So if you do not call alloc, or retain, you basically don’t own the objects, so you should not care about releasing them, as someone else will do…

    If you release them, the you’ll probably have a segfault, as releasing twice an object may lead to a double free…

    For instance:

    NSArray * myArray = [ NSArray emptyArray ];
    

    Auto-released object, by convenience method. You don’t own it, so you don’t have to release it.

    NSArray * myArray = [ [ NSArray emptyArray ] retain ];
    

    You’ll have to release the array, as you retained it.

    NSArray * myArray = [ [ NSArray alloc ] initWithArray: someArray ];
    

    Same here, as you explicitly allocated the array.

    NSArray * myArray = [ [ [ NSArray alloc ] initWithArray: someArray ] autorelease ];
    

    No need to release here, as the object has been placed in the auto-release pool, and will receive a release message automatically.

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

Sidebar

Related Questions

I'm a complete Xcode/Objective-C/Cocoa newbie but I'm learning fast and really starting to enjoy
I'm starting out on objective-C and so far I was under the belief that
Starting from ASP.NET MVC Preview 3, HTML.Button ( and other related HTML controls) are
Being a starting Objective-C developer, and not having the patience to actually do some
I'm starting Objective-C Development and I'm trying to wrap my head around how some
I'm starting to use objective C, and objective C mode works perfectly fine. However,
Im just starting getting into Objective-C, i'm trying to sort an array so it
I'm just starting to learn Objective-C using GNUstep on Windows and I'm wondering what
I am interested in searching a string (using objective-c) starting from a specific character
I've had a desire to learn at least a tiny bit about programming hardware

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.