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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:16:42+00:00 2026-05-24T04:16:42+00:00

I work on a project on iPhone iOS with Xcode 4. With Xcode >

  • 0

I work on a project on iPhone iOS with Xcode 4.

With Xcode > Product >Analyze I get 35 issues, all of this type:

 myTextField.text = [[NSString alloc] initWithFormat:@"0.2f", abc];

and the problem is “Potential leak of an object allocated at …”

What is the offending object and how can I release it?

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-05-24T04:16:42+00:00Added an answer on May 24, 2026 at 4:16 am

    You’re leaking the string that you’re assigning to myTextField.text. When this assignment happens, a copy is being made (look at the property definition in the documentation). In most cases, when values are immutable, as is the case with NSStrings, a copy will give you an instance that points to the same location as the object that is being copied, with the retain count incremented by 1.

    In the case of your code:

    myTextField.text = [[NSString alloc] initWithFormat:@"0.2f", abc];
    

    The retain count of the string that you’ve allocated is 2.

    You will either need to (1) release, (or autorelease) the string, or (2) use one of the NSString convenience methods, e.g. stringWithFormat: to create the string. This will give you an autoreleased string so you won’t have to worry about explicitly releasing it.

    (1)

    NSString *str = [[NSString alloc] initWithFormat:@"0.2f", abc];
    myTextField.text = str;
    [str release]
    

    or

    myTextField.text = [[[NSString alloc] initWithFormat:@"0.2f", abc] autorelease];
    

    (2)

    myTextField.text = [NSString stringWithFormat:@"0.2f", abc]; // autoreleased
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I work on a project for iPhone iOS 4 with Xcode 4. I have
I work on a iPhone project with iOS 4 and Xcode 4. In a
i've implemented this OpenCV build into my iphone project: http://aptogo.co.uk/2011/09/opencv-framework-for-ios/ It builds successfully and
I've been working on an iPhone project with iOS 4.0. I just downloaded Xcode
I work on a project for iPhone iOS4 with Xcode 4. I created a
I've got an iPhone project and my english Localizable.strings suddenly doesn't work anymore. I
I am using Xcode 3.2.1 in project, where Base SDK is iPhone Device 3.0
This is a new iPhone project, only 1 target (different from this question )
I am developing an iphone project on xcode and I'd like to commit my
I'm prepping for a simple work project and am trying to familiarize myself with

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.