Skip to content

Instantly share code, notes, and snippets.

@CodeIQ
Created October 10, 2012 05:24
Show Gist options
  • Save CodeIQ/3863315 to your computer and use it in GitHub Desktop.
Save CodeIQ/3863315 to your computer and use it in GitHub Desktop.
Find Memory Leaks
//
// MemoryLeakTestTableViewController.m
// MemoryLeakTest
@interface MemoryLeakTestTableViewController : UITableViewController
{
NSMutableArray *dataForCellArray1;
}
@property (retain, nonatomic) NSMutableArray *dataForCellArray2;
@property (retain, nonatomic) NSMutableArray *dataForCellArray3;
@property (retain, nonatomic) NSMutableArray *dataForCellArray4;
@property (retain, nonatomic) NSMutableArray *sections;
@end
@implementation MemoryLeakTestTableViewController
@synthesize dataForCellArray2;
@synthesize dataForCellArray3;
@synthesize dataForCellArray4;
@synthesize sections;
- (void)dealloc
{
[dataForCellArray1 release];
[dataForCellArray2 release];
[dataForCellArray3 release];
[super dealloc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *dataForCellArray = [NSMutableArray array];
for (int i = 0; i < 10; i++) {
[dataForCellArray addObject:[NSString stringWithFormat:@"Cell Row %d", i]];
}
dataForCellArray1 = [dataForCellArray mutableCopy];
self.dataForCellArray2 = [dataForCellArray mutableCopy];
self.dataForCellArray3 = [[NSMutableArray alloc] initWithArray:dataForCellArray];
self.dataForCellArray4 = [[[NSMutableArray alloc] initWithArray:dataForCellArray] autorelease];
self.sections = [[[NSMutableArray alloc] init] autorelease];
for (int i = 0; i < 4; i++) {
[self.sections addObject:[NSString stringWithFormat:@"dataForCellArray%d", i]];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.sections count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [self.sections objectAtIndex:section];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0) {
return [dataForCellArray1 count];
} else if (section == 1) {
return [dataForCellArray2 count];
} else if (section == 2) {
return [self.dataForCellArray3 count];
} else if (section == 3) {
return [self.dataForCellArray4 count];
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if (indexPath.section == 0) {
cell.textLabel.text = [dataForCellArray1 objectAtIndex:indexPath.row];
} else if (indexPath.section == 1) {
cell.textLabel.text = [dataForCellArray2 objectAtIndex:indexPath.row];
} else if (indexPath.section == 2) {
cell.textLabel.text = [self.dataForCellArray3 objectAtIndex:indexPath.row];
} else if (indexPath.section == 3) {
cell.textLabel.text = [self.dataForCellArray4 objectAtIndex:indexPath.row];
}
return cell;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment