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

  • Home
  • SEARCH
  • 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 6103551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:44:30+00:00 2026-05-23T13:44:30+00:00

I read almost every Question here on SO about memory management that involves NSStrings,

  • 0

I read almost every Question here on SO about memory management that involves NSStrings, but I can’t really solve this problem.

@interface:

@property (nonatomic, retain) NSString *criticalTranscription;

@implementation:
viewDidLoad:

criticalTranscription = [[NSString alloc] init];

NSArray *paragraphs = [doc valueForKeyPath:@"critical.text"];
for(int i = 0; i < [paragraphs count]; i++) 
{
    criticalTranscription = [criticalTranscription stringByAppendingString:[[paragraphs objectAtIndex:i] valueForKey:@"p"]];
    criticalTranscription = [criticalTranscription stringByAppendingString:@"\n\n"];
}
[transcription setText:criticalTranscription];

@XIB
A UISegmentedControl with an IBAction linked to:

- (IBAction) changeText:(id)sender
{
  if(transcriptionSelector.selectedSegmentIndex == 1)
    [transcription setText:diplomaticTranscription];
  else
    [transcription setText:criticalTranscription];
}

When I change the value of the UISegmentControl (first thing right after loading, nothing else runs), I run into this error (NSZombieEnabled=YES):

2011-07-07 01:10:43.639 Transcribe[404:707] *** -[CFString length]: message sent to deallocated instance 0x1189300

I can’t see anything relevant in the backtrace. Without NSZombieEnabled criticalTranscription just points to random arrays or something else. There is no further usage of the variable or any releases.

I ran analyze without any suspicious leaks.

What’s the problem?

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

    The problem is that you are overwriting a reference to a string that you own with one that you don’t own.

    // you own the empty string returned here
    criticalTranscription = [[NSString alloc] init]; 
    
    NSArray *paragraphs = [doc valueForKeyPath:@"critical.text"];
    for(int i = 0; i < [paragraphs count]; i++) 
    {
        // immediately overwrite allocated instance (that you own)
        criticalTranscription = [criticalTranscription stringByAppendingString:[[paragraphs objectAtIndex:i] valueForKey:@"p"]];
        criticalTranscription = [criticalTranscription stringByAppendingString:@"\n\n"];
    }
    

    However, don’t use this approach, because it pollutes the autorelease pool with unnecessary strings. Instead, use a mutable string and append strings to the single mutable string instance.

    Also, in order to utilise the property’s built-in memory management, you need to use self.criticalTranscription and not just criticalTranscription. Without the self., you are using the instance variable directly.

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

Sidebar

Related Questions

Almost every article I read told me that you can't have chdir in Java.
Almost every Java book I read talks about using the interface as a way
I've read many different things about correct memory management for cocoa/objective-c For instance ive
I dont know if I'm right, but allmost everytime I read about obfuscation and
I am new here and got a question that is tricking me all day
I read and reread the relevant clauses about ODR in the C++ standard, but
I understand that there has been countless of question posted here regarding opacity issues
I already read/tried these posts but that didn't help: Display multiple lines within a
I read this PHP RegEx page , but either I'm missing something, misreading something,
I read somewhere once that the modulus operator is inefficient on small embedded devices

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.