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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:10:10+00:00 2026-05-19T13:10:10+00:00

Here are two pieces of Objective-C code in a Foundation app. This piece of

  • 0

Here are two pieces of Objective-C code in a Foundation app. This piece of code is in a function:

    [arrayOfObjects addObject:[[TheShape alloc] init]];
    NSLog(@"%@", arrayOfObjects); // log verifies "<TheShape..." is in the array
    [arrayOfObjects release];

and in my TheShape class, I have this dealloc override method:

    - (void)dealloc {
        NSLog(@"TheShape dealloc called.");
        [super dealloc];
    }

Although my program works otherwise, it doesn’t work the way I expect it to. When the [arrayOfObjects release] message is sent, I expect to see the “TheShape dealloc…” string appear in the log. It doesn’t.

Q1: Why not?

So I dig a bit and simplify things. If I do something simpler like this:

    TheShape *aShape = [[TheShape alloc] init];
    [aShape release];

the debug message still doesn’t appear in the log.

Q2: Why not?

But if I do this:

    TheShape *aShape = [TheShape new];
    [aShape release];

the debug message does appear in the log. The debug message also appears in the log if I change the alloc/init in the first sample to new, too.

Q3: Why?

Obviously, I’m missing something conceptual in the alloc/init/release cycle (Q’s 1 and 2) and in the supposed equivalency of new and alloc/init (Q3). Can anybody point me to a tutorial that explains things a bit more for the hard of thinking, like me?

Thanks,

Bill

  • 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-19T13:10:10+00:00Added an answer on May 19, 2026 at 1:10 pm

    By any chance did you override +new on your class? It should be doing precisely the same thing as +alloc/-init.

    In any case, your very first line

    [arrayOfObjects addObject:[[TheShape alloc] init]];
    

    is leaking your TheShape instance. You should turn that in to

    [arrayOfObjects addObject:[[[TheShape alloc] init] autorelease]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here are two different pieces of code This is what I started with Vector2
I'm trying to run two pieces of code within the $(document).ready(function() { of jquery.
Here are two chunks of code that accomplish (what I think is) the same
Following are two pieces of jquery code. First one prints a text message when
Can someone summarise the key pieces of objective-c code that would assist in solving
I have two pieces of code that I'm using to learn about multiprocessing in
Here's a piece of Oracle code I'm trying to adapt. I've abbreviated all the
What is the corresponding Java code for this piece of C# code? public static
I have two pieces of code in Jsfiddle. One works and the other one
I ran the following two pieces of code on Windows XP (Code:Block, MinGW), and

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.