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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:20:55+00:00 2026-05-21T05:20:55+00:00

I am trying to sort an array of countries. This way works, but I

  • 0

I am trying to sort an array of countries. This way works, but I can’t figure out the way to release tmpArray. How do I release it and is there a better way of doing this?

// PUT COUNTRIES IN ARRAY
NSString *myFile = [[NSBundle mainBundle] pathForResource:@"Countries" ofType:@"plist"];
NSArray *tmpArray = [[NSArray alloc] initWithContentsOfFile:myFile]; 
tmpArray = [tmpArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];  
arrayCountries = [[NSArray alloc] initWithArray:tmpArray] ;
   //   [tmpArray release];
  • 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-21T05:20:55+00:00Added an answer on May 21, 2026 at 5:20 am

    Either -autorelease the one you alloc/init’d (because you’re losing your reference to it when you replace it with the sorted array) or use another variable like ‘sortedTmpArray‘.

    What you’re currently doing is “create this object and assign it to tmpArray“, then “create another array by filtering this one and assign it to tmpArray“. At that point, you no longer have a pointer to the first array you created so there’s no way to release it – it’s leaked.

    The solution is to place it in the autorelease pool when you create it or just use two separate pointers. Alternatively, you can create a mutable array the first time and use -sortUsingDescriptors: to sort it in place instead of creating two separate arrays.

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

Sidebar

Related Questions

I am trying to sort a multidimensional array, but am not sure if this
iam trying to sort this array by array[key]['premium']['Monthly'] and if there are two Monthly
I am trying to sort array with usort, but it doesn't work, What am
Trying to sort this array of objects according to (1) depth and (2) weight,
I'm trying to sort a multidimensional array in objective-c i know that i can
I am trying to sort a two-dimensional array by a timestamp column Descending. This
I'm trying to sort an array that looks like this: var dateGroups = [
I'm trying to sort an array in descending order in Java using this code:
I am trying to sort an array of strings, but it's not sorting anything....
I'm trying to sort an array that would look something like this: (please ignore

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.