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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:22:22+00:00 2026-05-29T13:22:22+00:00

So I presume this is a memory issue, here’s the code: – (NSString *)giveMeAStringGoddammit

  • 0

So I presume this is a memory issue, here’s the code:

- (NSString *)giveMeAStringGoddammit
{  
  NSString *s;
  // switch statement to choose which string to assign to s, so essentially:
  s = @"a string";      
  return s;  
}

And the calling code:

NSString *aString;
aString = [self giveMeAStringGoddammit];

However after this call, aString has an invalid summary when debugged and crashes when run.
I suspect I’m missing a retain or something, can someone help? Thanks.

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

    What you’ve got works just fine:

    #import <Foundation/Foundation.h>
    
    @interface Test : NSObject
    - (NSString *)giveMeAStringGoddammit;
    @end
    
    @implementation Test
    - (NSString *)giveMeAStringGoddammit
    {  
        NSString *s;
        // switch statement to choose which string to assign to s, so essentially:
        s = @"a string";      
        return s;  
    }
    @end
    
    int main (int argc, const char * argv[])
    {
        @autoreleasepool {
            Test *t = [[Test alloc] init];
            NSLog(@"t says: %@", [t giveMeAStringGoddammit]);
        }
        return 0;
    }
    

    The output of this program is:

    t says: a string
    

    To make this a little more realistic, let’s change it to use a property:

    #import <Foundation/Foundation.h>
    
    @interface Test : NSObject
    @property(copy, nonatomic) NSString *string;
    - (NSString *)giveMeAStringGoddammit;
    @end
    
    @implementation Test
    @synthesize string;
    - (NSString *)giveMeAStringGoddammit
    {  
        NSString *s;
        // switch statement to choose which string to assign to s, so essentially:
        s = self.string;
        return s;  
    }
    @end
    
    int main (int argc, const char * argv[])
    {
        @autoreleasepool {
            Test *t = [[Test alloc] init];
            t.string = @"Hello world!";
            NSLog(@"t says: %@", [t giveMeAStringGoddammit]);
        }
        return 0;
    }
    

    This does what you’d expect:

    t says: Hello world!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a curl class, called Curl. Let's presume i have this code: $url
I have this (attached)code which works perfectly on all the AVDs I create with
I know this is possible to be done using javascript, and I presume I
Let's presume that I have string like '=&?/;#+%' to be a part of my
Say you have records in a text file which look like this: header data1
I want to make a sequence of in-memory operations atomic. I presume there is
Suppose there is this code: class CFoo { public: CFoo() { iBar = new
I've written a library in C which consumes a lot of memory (millions of
I presume this is possible? Basically i am receiving using LINQ (LINQ2Entities Entity Framework)
I presume this is a configuration error somewhere, but I can't figure out where.

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.