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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:16:28+00:00 2026-05-13T16:16:28+00:00

I seem to have a fundamental gap in my memory management understanding. The code

  • 0

I seem to have a fundamental gap in my memory management understanding. The code below is located within a singleton that gets called multiple times within my app to parse data that is downloaded from the web. For each article I download, I allocate a mutable string, then do tons of parsing, then write the file to the file system for later display in a UIWebView.

But every time I enter this method, I allocate a new “articleString”. And I never release this string. I think this is a leak, but if I add a release at the bottom of this method (after the file is written), my app crashes the next time this method is called. I don’t understand why it crashes, since another NSMutableString is allocated next time it is called.

UPDATE: I do release articleString in the dealloc method. But it still seems that I should release at the end of this method, since I alloc every time I enter.

UPDATE: articleString is defined as follows in the header:

@property (nonatomic, retain) NSMutableString *articleString;

the parseArticle method below is a placeholder for a series of methods that manipulate articleString.

 self.articleString = [[NSMutableString alloc] initWithData:articleData encoding:NSUTF8StringEncoding];

 //Parse the article for display
 [self parseArticle];

 //Write the article string to a file for later display
 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
 NSString *documentsDirectory = [paths objectAtIndex:0];
 NSString *path = [documentsDirectory stringByAppendingPathComponent:@"article.html"];
 NSLog(@"%@", articleString);
 [articleString writeToFile:path atomically:YES];
  • 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-13T16:16:28+00:00Added an answer on May 13, 2026 at 4:16 pm

    I like to let properties handle this for me. If the articleString property is set to retain then this is simple.

    self.articleString = [[[NSMutableString alloc] initWithData:articleData encoding:NSUTF8StringEncoding] autorelease];
    
    [self doStuff];
    

    Then

    - (void)dealloc {
        self.articleString = nil;
        [super dealloc]
    }
    

    article string will get released and properly retain when you set a new one. And it will be cleaned up on dealloc.

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

Sidebar

Related Questions

I seem to have a problem understanding how to conditionally test a boolean value
I have some fundamental points/questions about OpenGL, not all involving code but concepts as
I have quite a fundamental problem that none of my selenium phpunit tests pass
I seem to be missing something quite fundamental here and yet my code doesn't
I have inherited an application that uses the ASP.NET membership provider for user management.
I have a question which seems to be rather fundamental but I can't seem
I seem to have a problem with getting MVC to fill in my custom
I seem to have the exact opposite problem than this question on stopping dock
I seem to have missed something - in this step through it talks through
I seem to have an issue with connecting to an embedded FireBird database from

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.