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 created a iPhone static library project with two targets like this Project -->
I am using Xcode 3.2.1 in project, where Base SDK is iPhone Device 3.0
I'm trying to work through Project Euler and I'm hitting a barrier on problem
I work on a project that uses multiple open source Java libraries. When upgrades
I'm starting work on a project using Rails, but I'm waiting for the 3rd
I recently had to work on a project where the previous developer modified the
I've started work on a project that will be primarily acting as a Sync
I've been doing a project at work recently focused on an almost entirely client-driven

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.