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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:13:01+00:00 2026-05-31T17:13:01+00:00

I have a case where I’m declaring an NSMutableArray and then testing it like

  • 0

I have a case where I’m declaring an NSMutableArray and then testing it like so:

-(void)whatever {
    NsMutableArray *array;

    for(int i = 0; i < 10; i++) {
        if(array){
            [array release];
        }
        array = [[NsMutableArray alloc] init];
        // Add things to the array and do stuff with those things before starting over
    }
    if ([array count] > 0) {
        // Do something else
    }
}

For some reason the if(array){} is evaluating to YES and it’s trying to release an object that doesn’t exist yet on the first pass through. It also evaluates to YES if I try if(array != nil){}. Is there a better way to test this?

  • 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-31T17:13:02+00:00Added an answer on May 31, 2026 at 5:13 pm

    When you declare your array set it to nil:

    NSMutableArray *array = nil;
    

    Otherwise you can get junk in the pointer.

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

Sidebar

Related Questions

I have a Case-When clause like this; (CASE WHEN A.YAZ_ADRES IS NULL THEN (B.IS_ADRES1
how can i optimized this code? i dont like to have case statement, is
I have a case where I'd like to be able to allow the users
I have case where the class hierarchy is something like this, +---------------+ | UIElement
I have a case here that I would like to have some opinions from
I have a case that uses view inheritance, and my code looks essentially like:
I have a case statement that goes a little something like this: case @type
I have a case where I should get the elements from an array and
I have a case where I would like to catch an update event on
We have a case where we are testing a swing application. We have a

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.