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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:10:40+00:00 2026-05-29T06:10:40+00:00

I have this method: -(NSString *)scrambleWordGenerator: (NSUInteger)length { NSMutableString *scrambledWord = [[NSMutableString alloc] initWithString:@];

  • 0

I have this method:

-(NSString *)scrambleWordGenerator: (NSUInteger)length {
    NSMutableString *scrambledWord = [[NSMutableString alloc] initWithString:@""];
    for (int i = 0; i < length; i++) {
        NSUInteger randomIndex = arc4random() % [self.arrayOfCharacters count];
        NSString *randomCharacter = [NSString stringWithString:[self.arrayOfCharacters objectAtIndex:randomIndex]];
        [scrambledWord insertString:randomCharacter atIndex:i];
    }
    NSString *finalWord = [[NSString alloc] initWithString:scrambledWord];
    [scrambledWord release];
    return finalWord;
}

It works, swimmingly in fact, however upon using Xcode’s “Analysis” feature, it says that finalWord has a potential memory leak.

I thought when creating a NSString with a prefab init method that the string will be autoreleased. What am I missing? Below is a screen grab of the error:

enter image description here

edit

The method now looks like this:

-(NSString *)scrambleWordGenerator: (NSUInteger)length {
    NSMutableString *scrambledWord = [[NSMutableString alloc] initWithString:@""];
    for (int i = 0; i < length; i++) {
        NSUInteger randomIndex = arc4random() % [self.arrayOfCharacters count];
        NSString *randomCharacter = [NSString stringWithString:[self.arrayOfCharacters objectAtIndex:randomIndex]];
        [scrambledWord insertString:randomCharacter atIndex:i];
    }
    NSString *finalWord = [NSString stringWithString:scrambledWord];
    [scrambledWord release];
    return finalWord;
}

And no more errors!

  • 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-29T06:10:40+00:00Added an answer on May 29, 2026 at 6:10 am

    No, the moment you use alloc, you’re responsible for releasing it – either by release or by moving it to autorelease pool via autorelease.

    It would be on the autorelease pool if you used [NSString stringWithString:] instead.

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

Sidebar

Related Questions

I have this method. [self postRequestWithURL: (NSString *) postArgs:(NSDictionary *) headerArgs: (NSDictionary *) ];
I have this method call I have to use... financial_document.assets.length But financial_document.assets could be
In my iOS iPhone app I have this method: -(id)initWithLocationName:(NSString *)locatNm latitude:(double)lati longitude:(double)longi xCoord:(double)xco
I have this method: - (void)postDictionary:(NSDictionary *)dictionary toURL:(NSURL *)url forDelegate:(id)delegate withIdentifier:(NSString *)identifier; I want
I Create a class named DataClass there i have this method +(NSMutableArray*) returnList :(NSString
I have this method... - (void) helloThere: (int) myValue { // I am trying
I have this method on a webpart: private IFilterData _filterData = null; [ConnectionConsumer(Filter Data
I have this method in my db class public function query($queryString) { if (!$this->_connected)
I have this method: public bool CanExecute() And after 70 commits, I added an
I have this method Verify_X which is called during databind for a listbox selected

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.