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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:48:09+00:00 2026-05-24T00:48:09+00:00

Xcode is telling me that there are some problems with the code below in

  • 0

Xcode is telling me that there are some problems with the code below in terms of memory leaking.

@property (nonatomic, retain) NSMutableArray *naw_rows;

-(void) loadTableRows:(BOOL)shouldReload
{
    [naw_rows removeAllObjects];

  [self.naw_rows addObject: [[CellModel alloc] initialize:@"name"     title:@"Name"          value: self.currentProfile.name]];
  [self.naw_rows addObject: [[CellModel alloc] initialize:@"company"  title:@"Company name"  value: self.currentProfile.company]];
  [self.naw_rows addObject: [[CellModel alloc] initialize:@"address"  title:@"Address"         value: self.currentProfile.address]];
  [self.naw_rows addObject: [[CellModel alloc] initialize:@"zipcode"  title:@"Zipcode"      value: self.currentProfile.zipcode]];
  [self.naw_rows addObject: [[CellModel alloc] initialize:@"city"     title:@"City"        value: self.currentProfile.city]];
}

// here is my cellModel object:
@implementation CellModel

-(id) initialize:(NSString *)newName title:(NSString *)newTitle value:(NSString *)newValue;
{
    if (self == [super init])
    {
        name = newName;
        title = newTitle;
        value = newValue;
    }
    return self;
}

- (NSString *) getName
{
   return name;
}

- (NSString *) getTitle
{
    return title;
}

- (NSString *) getValue
{
    return value;
}

-(void)dealloc
{
    [super dealloc];
}

@end;

All the addObject lines give the following error:

Potential leak of an object allocated on line — Method returns an
Objective-C object with a +1 retain count (owning reference) Object
allocated on line — is not referenced later in this execution path
and has a retain count of +1 (object leaked)

In other topics about memory leaking i found that this would be the correct way to do this:

CellModel *model = [[CellModel alloc] initialize:@"name" title:@"Name" value: self.currentProfile.name];
[self.naw_rows addObject: model];
[model release];

But this gives me the following error:

Incorrect decrement of the reference count of an object that is not
owned at this point by the caller

So what am i doing wrong? In my first piece of code the retain count should be 1. Owned by the array. And i assume the objects are released when i use [array remodeAllObjects]

Thanks in advance,

Nico

  • 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-24T00:48:10+00:00Added an answer on May 24, 2026 at 12:48 am

    This leaks:

    [self.naw_rows addObject: [[CellModel alloc] initialize:@"name"     title:@"Name"          value: self.currentProfile.name]];
    

    You own the object returned by alloc-init and you are responsible for relinquish ownership of it by sending it a release or autorelease message, which you fail to do.

    Using a temporary variable, as you propose, does solve the problem:

    CellModel *model = [[CellModel alloc] initialize:@"name" title:@"Name" value: self.currentProfile.name];
    [self.naw_rows addObject: model];
    [model release];
    

    So, why does the analyzer complain? Because of the name of your initializer. Rename it to something like initWithName:title:value: and you’ll see the “Incorrect decrement of the reference count of an object that is not owned at this point by the caller” go away.

    The convention is that the name of initializer methods should begin with the abbreviation init.

    Also, the implementation of your class does not assign self to the result of calling super’s initializer. This:

    if (self == [super init])
    

    should be:

    if ((self = [super init]))
    

    or, if you prefer:

    self = [super init];
    if (self)
    

    Also, the memory management of the instance variables of the CellModel class is wrong. You should retain or copy the objects passed as arguments to your init method and also release them in dealloc.

    The accessor methods also break the naming conventions, they should be named simply name, title, etc. The prefix “get” is only for methods that return objects indirectly.

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

Sidebar

Related Questions

XCode has been acting really, really strange recently. It is telling me that various
XCode accepts it. But will retain be applied when I internally set the property
Does Xcode support anything akin to Visual Studio style #region directives for arbitrary code
Xcode normally saves its executable configurations in the user specific .pbxuser file. Is there
Xcode keeps picking my developer provision. This is even if I pick Don't Code
Xcode has a nice feature that let you submit your application to iTunes connect
Xcode sets variety of environment variables related build when running shell script. Is there
Xcode has these handy time savers in the scripts menu called Code->Place Accessor Defs
Xcode looked at this line and did not complain. Project built, code crashed at
Xcode seems to split the code window and show the file name in the

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.