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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:43:59+00:00 2026-06-01T04:43:59+00:00

I use NSString to append strings, but when I release the cacheStr NSString, the

  • 0

I use NSString to append strings, but when I release the “cacheStr” NSString, the iphone simulator crash.
Where should I put the release code ?

init code : I use three NSString to append content of the dataArray.

NSMutableArray *dataArray = [[NSMutableArray alloc] init];
NSString *cacheStr = [[NSString alloc] init];
NSString *tmpStr = [[NSString alloc] init];
NSString *notiyStr = [[NSString alloc] initWithFormat:@"This is a test message!"];
dataArray = [NSArray arrayWithObjects:
                      @"currency1.png",
                      @"currency2.png",
                      @"currency3.png",
                      @"currency4.png",
                      @"currency5.png",
                      @"xxxxxx",
                      @"currency1.png",
                      @"currency2.png",
                      @"currency3.png",
                      @"currency4.png",
                      @"currency5.png",
                      @"xxxxxx",
                      nil];

append string code : use for loop to append strings.

int isFailed = 0;
int countOfDataArray = [dataArray count];
if (!isFailed) {
    for (int i=0; i < countOfDataArray; i++) {
        if ([[dataArray objectAtIndex:i] isEqualToString:@"xxxxxx"]) {
            tmpStr = [cacheStr stringByAppendingFormat:@"%@\n", [dataArray objectAtIndex:i]];
        }
        else {
            tmpStr = [cacheStr stringByAppendingFormat:@"value %d : %@\n", i+1, [dataArray objectAtIndex:i]];
        }
        cacheStr = [tmpStr copy];
        [tmpStr release];
    }
}
tmpStr = [notiyStr stringByAppendingString:cacheStr];

release code : when I add [cacheStr release], the simulator will crash...

[dataArray release];
[notiyStr release];
// [cacheStr release];     /*  crash ... */

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-06-01T04:44:01+00:00Added an answer on June 1, 2026 at 4:44 am

    its more simple to declare a NSString like this

    NSString *tmpStr = @"This is a test message!";

    then no need to release it,when you dont use alloc

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

Sidebar

Related Questions

I am trying to use NSString *myString = @NO; [myString writeToURL:[NSURL URLWithString:@http://example.com/text.txt] atomically:YES]; But
This is probably a question that is more about object alloc/retain/release, but I'll use
I want to when should we use NSString and when should we use the
When I use the this method to initialize a UITabBarItem : - (id)initWithTitle:(NSString *)title
When reading an NSString from a file I can use initWithContentsOfFile:usedEncoding:error: and it will
How do I use the % character literal in an NSString stringWithFormat ? I
I have to use scanf() for accepting name of user in NSString object. If
When I take a path in an NSString and turn around and use it
I have a simple function that returns an NSString after decoding it. I use
I'm just looking at NSString.h and wonder why some method declaration args use (NSString

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.