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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:21:54+00:00 2026-05-22T15:21:54+00:00

I have a Note class, and I have a Tuner Class. My Tuner class

  • 0

I have a “Note” class, and I have a Tuner Class. My Tuner class is initializing an NSArray* in it’s init function.

I want to initialize this array to hold 88 notes, and right now I am creating things like Note* key1; etc etc.

I am just making sure that I need to alloc things for these notes so that they do not go out of scope once init finishes, and my NSArray stays in tact with its entries, or am I able to just declare Note key1 and insert into the array and it is taken care of for me.
An example piece of code creating an NSArray containing a few objects such that the array will stay around even after the function exits would be very helpful. Thank you!

  • 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-22T15:21:55+00:00Added an answer on May 22, 2026 at 3:21 pm

    NSArray and NSMutableArray send -retain to objects when they are added, so the appropriate thing to do is to -release the objects you add explicitly or use autoreleased objects.

    Here’s a quick example for the Tuner class’s -init method:

    - ( id )init
    {
        NSInteger    i;
        Note         *note;
    
        self = [ super init ];
        if ( self ) {
            notes = [[ NSMutableArray alloc ] initWithCapacity: 88 ];
            for ( i = 0; i < 88; i++ ) {
                note = [[ Note alloc ] initWithKey: i ];
                [ notes addObject: note ];
                [ note release ];
            }
        }
    
        return( self );
    }
    

    You will need to +alloc every Note object and -release it, since adding it to the array retains it. To destroy all the note objects when you’re done, make sure your Tuner class releases the array in its -dealloc method:

    - ( void )dealloc
    {
        [ notes release ]; // this sends release to all objects in the array, too
    
        [ super dealloc ];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
Note that this function does not have a { and } body. Just a
I have 2 models: notes and tags. class Note < ActiveRecord::Base has_and_belongs_to_many :tags end
I have up to 4 files based on this structure (note the prefixes are
I have the VS2005 standard edition and MS says this: Note: The Windows Service
(Note: This is for MySQL's SQL, not SQL Server.) I have a database column
Let's say I have a simple stored procedure that looks like this (note: this
Note: This is the opposite direction to most similar questions! I have an iPhone
I have a singleton class for global access to config information. This singleton class
I have a class and methods inside it written in C#. I want to

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.