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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:22:43+00:00 2026-05-16T08:22:43+00:00

3 correlated questions: 1.Do the code snippets below provide the very same results in

  • 0

3 correlated questions:

1.Do the code snippets below provide the very same results in terms of memory?

NSBundle *bundle=[[NSBundle alloc] init];
[bundle release];
bundle=nil;

and

NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
NSBundle *bundle=[NSBundle mainBundle];
[pool drain];
pool=nil;
bundle=nil;

2.Why in

NSBundle *bundle=[[NSBundle alloc] init];
[bundle release];

the retainCount of bundle is 1, not 0?

3.Which is recommended: always use class methods, or always gain ownership by using alloc?

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-05-16T08:22:44+00:00Added an answer on May 16, 2026 at 8:22 am
    1. Yes, those should be equivalent in terms of memory management, from the developer’s point of view. The frameworks might be doing something behind the scene to hang on to [NSBundle mainBundle], but that’s not your concern.

    2. Ignore retainCount. waves hand That’s not the method you’re looking for. Once you have relinquished ownership of an object, either by invoking release or autorelease, then it is invalid (bad practice) to send more messages to that object. In your example, you alloc an NSBundle, so you own it. That means it has a +1 retain count (I say +1, because it’s relative). When you release the bundle, it now has a “0” retain count, which means you no longer own this object (despite whether or not it may still exist in memory), which means you should not send messages to it, under penalty of stuff blowing up in your face.

    3. What’s recommended is to use whatever’s appropriate for the situation. If you just need a temporary object, then using a class method that returns an autoreleased object is probably going to be just fine. If you need to be absolutely sure that the object isn’t going to go away while you’re using it, then you can use an alloc/init approach (or retain an autoreleased object) and then just release it when you’re done.

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

Sidebar

Related Questions

I have the correlated subquery below. Each id (147,148,149) in table1 has many records
I have a very simple code segment where there is a do while loop
UPDATED: I've updated the code based on the correct answer below. This works but
I have a correlated subquery in an update that used to work just fine
I am trying to write a simple correlated sub query that deletes all records
Thank you all for helping. Below this post I put the corrected version's of
I have 3 models: User has_many :questions has_many :corrections end Question has_one :correction belongs_to
I have looked through the other questions on here, and on other forums. The
I was reading through the network device driver code.My driver follows the driver-model.REF:kernel/Documentation/driver-model. Reading
A colleague has passed me an interesting code sample that crashes with an InvalidProgramException

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.