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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:36:18+00:00 2026-05-28T02:36:18+00:00

Following the StringCalculator kata from Xcode Katas , I ended up with a following

  • 0

Following the StringCalculator kata from Xcode Katas, I ended up with a following class.

@implementation StringCalculator

- (int) add: (NSString *) string {    
    // this is marked as a potential memory leak by the `Analyze` tool
    NSMutableString *separatorCharacters = [@"\n" mutableCopy];

    if ([string hasPrefix:@"//"]) {
        NSRange range = NSMakeRange(2, 1);
        NSString *additionalSeparator = [string substringWithRange:range];
        [separatorCharacters appendString:additionalSeparator];
    } else {
        [separatorCharacters appendString:@","];
    }

    NSCharacterSet *separators = [NSCharacterSet characterSetWithCharactersInString:separatorCharacters];
    NSArray *numbers = [string componentsSeparatedByCharactersInSet:separators];

    // [separatorCharacters release];

    int sum = 0;    
    for (NSString *number in numbers) {
        sum += [number intValue];
    }
    return sum;
}

@end

Everything works fine, but when I run Analyze, I’m getting a potential memory leak on the first line of the method. If I do a manual release at the end, it seems to satisfy the analyzer, but I don’t really understand why this is happening.

How does creating a mutableCopy differ from a substringWithRange, for example? I’m not sure how to check if I’m using ARC, but if I wasn’t, I should be leaking memory on every single line where I create a object right?

I also thought that calling release is kind of deprecated or unnecessary in ARC projects.

  • 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-28T02:36:18+00:00Added an answer on May 28, 2026 at 2:36 am

    If I do a manual release at the end, it seems to satisfy the analyzer

    You aren’t using ARC. Manual releasing is forbidden with ARC, this wouldn’t compile. Check your build settings.

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

Sidebar

Related Questions

Following on a bit from this question , if I have this class: private
Following on from this question what would be the best way to write a
Following up from this question: How can I unlock a file that is locked
Following on from a discussion which got going in the comments of this question
following code is used to find url from a string with php. Here is
Following on from another question I have asked I have created a new class
Following this python example , I encode a string as Base64 with: >>> import
Following class structure is given: class Job { String description; Collection<JobHistory> history; } class
Following suggestions on this site, I have adopted SimpleXML from org.simpleframework.xml. I use this
Following on from this question... how do you tell the visual studio project type

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.