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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:39:07+00:00 2026-05-28T05:39:07+00:00

I am working on an iphone application, and although I thought I had a

  • 0

I am working on an iphone application, and although I thought I had a good understanding of memory management, I’m seeing some issues after using the Xcode Analyze function. I have looked at many of the existing questions I could find on here, but I couldn’t find one that was similar to my situation.

CustomerDetailController.h

@interface CustomerDetailController : UITableViewController {
  PTCustomer *customer;
}
@property (nonatomic, retain) PTCustomer *customer;

- (id)initWithCustomer:(PTCustomer *)aCustomer;

CustomerDetailController.m

@synthesize customer;

- (id)initWithCustomer:(PTCustomer *)aCustomer {
  if ((self = [super initWithStyle:UITableViewStyleGrouped]))
  {
    if (aCustomer != nil)
      self.customer = aCustomer;
    else
      self.customer = [[PTCustomer alloc] init];  // This line shows Potential leak of an object allocated on line ##

  }
  return self;
}

If I click on the item marked by the Analyzer, it then says:

  1. Method returns an Objective-C object with a +1 retain count

  2. Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1

My reasoning behind this is that if a PTCustomer object was not passed in, I want to initialize a new one so that I have it available elsewhere within this class.

What is the correct way to do this?

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-28T05:39:08+00:00Added an answer on May 28, 2026 at 5:39 am

    self.customer is being over-retained.
    +1 for alloc of customer
    +1 when the property setter retains customer.

    Do not retain customer, the property setter will retain it.

    Just:

    self.customer = [[[PTCustomer alloc] init] autorelease];
    

    But given that this is an init method there is a strong argument that the ivar should be assigned directly:

    customer = [[PTCustomer alloc] init];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on iphone networking application.. I am using asihttp , a wrapper
I am working on iPhone application.. For the purpose of finding memory leaks I
I am working on an iphone application that needs to send some images over
I'm slowly working through the iPhone Application Programming Guide and although it's been great
I am working on an iPhone application which is crashing after the routine tied
Hi im working on iphone application using monotouch im trying to get list of
I am working on Iphone application and new to dev. I am sorry if
I'm working on iphone application which needs to run offline at an exhibition. It
I'm working on an iphone application (not web app) and I'd like to build
I am working on an iPhone Application that stores images in the Applications 'Document'

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.