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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:15:35+00:00 2026-05-16T00:15:35+00:00

I am using a custom class to display some info on a table view.

  • 0

I am using a custom class to display some info on a table view.
The problem is that as long as I scroll the tableview memory is leaking…

I guess I have something wrong at my class.

Please have a look:

    @interface Person : NSObject {

 NSString *name;
 NSString *surname;
 NSString *address;
 NSString *email;

}

@property (nonatomic, copy) NSString *name, *surname, *address, *email;



@implementation Person
@synthesize name, surname, address, email;

-(id)init {

 [super init];
 name = [[NSString alloc] init];
 surname = [[NSString alloc] init];
 address = [[NSString alloc] init];
 email = [[NSString alloc] init];
 return self;
}



- (void)dealloc
{
 [name release];
 [surname release];
 [address release];
 [email release];
 [super dealloc];
}


#import "Person.h"

@interface Group : NSObject {

 NSString *groupTitle;
 NSMutableArray *persons;

}

@property (readwrite, copy) NSString *groupTitle;

- (void)addPerson:(Person *)person;
- (void)removeAll;
- (NSArray *)getPersons;
- (int)PersonsCount;

@end




@implementation Group
@synthesize groupTitle;



-(id)init {

 [super init];
 persons = [[NSMutableArray alloc] init];
 return self;
}


-(void)addPerson:(Person *)person {


 [persons addObject:person];

}

-(void)removeAll {

 [persons removeAllObjects];

}

-(NSArray *) getPersons {

 return [persons copy];
 [persons release];


}

-(int)personsCount {

 return [persons count];

}

-(void)dealloc {

 [groupTitle release], groupTitle = nil;
 [persons release], persons = nil;
 [super dealloc];
}


@end




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

  …….


  Group *groupForRow = [[Group alloc] init];
  Person *personForRow = [[Person alloc] init];
  personForRow = [[groupForRow getPersons] objectAtIndex:indexPath.row];

  _personName = personForRow.name;
  _personSurname = personForRow.surname;
  _personAddress = personForRow.address;
  _personEmail = personForRow.email;


  [groupForRow release], groupForRow = nil;
  [personForRow release], personForRow = nil;

  …..

  return cell
  • 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-16T00:15:36+00:00Added an answer on May 16, 2026 at 12:15 am

    Few corrections (read the comments):

    @interface Person : NSObject {
        NSString *name;
        NSString *surname;
        NSString *address;
        NSString *email;
    }
    
    // copy is OK for strings...
    @property (nonatomic, copy) NSString *name, *surname, *address, *email;
    
    @end
    
    
    @implementation Person
    
    @synthesize name, surname, address, email;
    
    - (id)init {
        if (self = [super init]) {
            // There is no need to allocate the strings
            // In addition, once you write 'name = [[NSStrin alloc] init];' you don't use the property.
            // If you do want to use the property setter then you should write 'self.name = @"some string";'
        }
        return self;
    }
    
    
    - (void)dealloc {
        [name release];
        [surname release];
        [address release];
        [email release];
        [super dealloc];
    }
    
    @end
    
    
    #import "Person.h"
    
    @interface Group : NSObject {
        NSString *groupTitle;
        NSMutableArray *persons;
    }
    
    // Any special reason for "readwrite" instead of "nonatomic"?
    @property (readwrite, copy) NSString *groupTitle;
    // This property is more important than the string:
    @property (nonatomic, retain) NSMutableArray *persons;
    
    - (void)addPerson:(Person *)person;
    - (void)removeAll;
    - (NSArray *)getPersons;
    - (int)PersonsCount;
    
    @end
    
    
    @implementation Group
    
    @synthesize groupTitle, persons;
    
    - (id)init {
        if (self = [super init]) {
            // Use the autoreleased array instance ([NSMutableArray array]) and set it to the property setter that will retain the object:
            self.persons = [NSMutableArray array];
        }
        return self;
    }
    
    
    - (void)addPerson:(Person *)person {
        // I prefer using properties (the "self." in the beginning) instead of the members directly...
        [self.persons addObject:person];
    }
    
    - (void)removeAll {
        [self.persons removeAllObjects];
    }
    
    // I think that this getter is unnecessary - use the property instead...
    - (NSArray *) getPersons {
        // There is no need to copy
        return [persons copy];
        // Don't you have a warning for this line? It is never executed
        [persons release];
    }
    
    - (int)personsCount {
        return [self.persons count];
    }
    
    - (void)dealloc {
        [groupTitle release], groupTitle = nil;// The "groupTitle = nil" is unnecessary.
        [persons release], persons = nil;// The "persons = nil" is unnecessary.
        [super dealloc];
    }
    
    @end
    
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        …….
    
    
        Group *groupForRow = [[Group alloc] init];// Do you REALLY have to allocate this object each "cellForRowAtIndexPath"??
        Person *personForRow = [[Person alloc] init];// Get rid of the "= [[Person alloc] init]" - this is a leak (because of the next line)
        personForRow = [[groupForRow getPersons] objectAtIndex:indexPath.row];// If you will use the property persons instead of the "getPersons" (that copies the array) then you will get rid of another leak
    
        // What are these?
        _personName = personForRow.name;
        _personSurname = personForRow.surname;
        _personAddress = personForRow.address;
        _personEmail = personForRow.email;
    
        // The " = nil" is unnecessary here...
        [groupForRow release], groupForRow = nil;// If you won't allocate the group then you won't need this line...
        [personForRow release], personForRow = nil;// NSZombie - you release object that you don't owe (do you have crashes, that you don't know why they are happen?)
    
        …..
    
        return cell;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 499k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Google has been experimenting with this feature in the developer… May 16, 2026 at 12:28 pm
  • Editorial Team
    Editorial Team added an answer Missing evt in function parameter: $('input[name=Qty]').keyup(function(evt) { ^ May 16, 2026 at 12:28 pm
  • Editorial Team
    Editorial Team added an answer :%s~<Validator>.*</Validator>~~g Does the trick May 16, 2026 at 12:28 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Ok so this problem is baffling me. I have a custom class that all
I am currently stuck with this problem of displaying an image using HtmlHelper class.
The problem is mostly summed up in the title. I am using the custom
I am using a custom class based off RelativeLayout but it obviously doesn't render
I have a custom class that I've written that extends ImageView (for Android Java).
I am using a custom subclass of JPanel to offer me more control over
I have a popup menu that displays dynamically created custom JPanel objects in a
MVC2 comes with a nice sample of a validation attribute called PropertiesMustMatchAttribute that will
I am working on building a HTML5 video player with a custom interface, but
Suppose I have this model: public class ViewModel { [Required] public string UserInput {

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.