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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:21:51+00:00 2026-05-25T03:21:51+00:00

XCode is reporting a memory leak on a specific line of code: (NSArray*)myFunction{ NSMutableArray

  • 0

XCode is reporting a memory leak on a specific line of code:

(NSArray*)myFunction{
   NSMutableArray * tempMapListings=[[NSMutableArray alloc] init]; //Xcode says leak is here

   //do a bunch of stuff to insert objects into this mutable array


    return tempMapListings;
    [tempMapListings release]; // but I release it ?!

   }

Is this due to releasing as an NSArray an mutable array? Since mutable inherits from inmutable, I wouldn’t think this is a problem, and in any case, the object is released anyway. I’d appreciate the advice of a second eye.

  • 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-25T03:21:52+00:00Added an answer on May 25, 2026 at 3:21 am

    You’re releasing tempMapListings after your return from the function. After a return statement, no more code is executed on that branch. Ergo, your [tempListListings release] statement is never run. Moreover, as you’re returning it, you don’t actually want to release it straight away – the caller will never have a chance to retain the array!

    Autorelease pools are your friend here. Objects added to an autorelease pool are released on your behalf “eventually”, giving your caller time to grab the result. To add your object to the default pool, change your allocation line to

    NSMutableArray *tempMapListings = [[[NSMutableArray alloc] init] autorelease];
    

    and remove that last release call.

    For more information on autorelease pools, have a read of Apple’s documentation. They’re really quite useful.

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

Sidebar

Related Questions

Xcode looked at this line and did not complain. Project built, code crashed at
Does Xcode support anything akin to Visual Studio style #region directives for arbitrary code
Xcode question here: If I'm programming in C++ or objective-C, and I #include or
XCode frequently seems to lose it's mind, and doesn't color code system classes or
Using XCode 4.2, I am using the static analyser on code similar to the
Xcode has these handy time savers in the scripts menu called Code->Place Accessor Defs
I have a really weird problem with Xcode 3.2.5 In a normal code sequence
Xcode normally saves its executable configurations in the user specific .pbxuser file. Is there
Xcode keeps picking my developer provision. This is even if I pick Don't Code
Can somebody help me trace these CoreVideo memory leaks when running Instruments in XCode?

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.