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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:39:25+00:00 2026-05-24T19:39:25+00:00

The following method takes a double pointer to NSString and populates this with a

  • 0

The following method takes a double pointer to NSString and populates this with a value, as follows:

@implementation Exp
- (int) func:(NSString**) dpStr
{
    //------
    *dpStr = [self func_2];
    //------
}

Now it is being called like this:

int main ()
{
   NSString * str = [[NSString alloc] init];
   int retCode = [Exp func:&str];
   // <----- Now here I'm able to access value returned by func ------->

   [str release];    //  <--- It is crashing here 
}

Can anyone explain why it is crashing?

  • 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-24T19:39:26+00:00Added an answer on May 24, 2026 at 7:39 pm

    This allocates an empty string:

    NSString * str = [[NSString alloc] init];
    

    This replaces the previous value of str with a new string which is apparently already autoreleased; the old value of str is leaked:

    int retCode = [Exp func:&str];
    

    This attempts to release the new value of str, which is already balanced, so it’s an overrelease and a crash happens:

    [str release];
    

    Neither the leading +alloc/-init nor the trailing -release are needed in this case, as the object is provided by -func:. All you need is:

    NSString *str = nil;
    [Exp func:&str];
    // use str normally
    

    Better would be to modify -func: to return the string directly:

    NSString *str = [Exp func];
    // use str normally
    

    Then there is no need to pass it by address.

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

Sidebar

Related Questions

Let's say I have the following method: public static int CountNonNullMembers<T>(this IEnumerable<T> enumerable) {
My problem is the following. I have a method which simply takes an XML
The following instance method takes a file path and returns the file's prefix (the
Take the following C# method: static double[] AddArrays(double[] left, double[] right) { if (left.Length
I have a following method which takes a XDocument, iterates through the nodes and
The following method does not work because the inner block declares a variable of
The following method does not compile. Visual Studio warns An out parameter may not
The following method, when called with something like String val = getCell(SELECT col FROM
The following method is launched from the constructor of UserControl. A cross thread exception
The following method does not apply the wpf changes (background = red) until the

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.