Skip to content

Instantly share code, notes, and snippets.

@CodeIQ
Created October 10, 2012 05:24

Revisions

  1. @JFK JFK revised this gist Oct 10, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gistfile1.matlab
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    // MemoryLeakTestTableViewController.m
    // MemoryLeakTest

    @interface MemoryLeakTestTableViewController ()
    @interface MemoryLeakTestTableViewController : UITableViewController
    {
    NSMutableArray *dataForCellArray1;
    }
    @@ -30,17 +30,17 @@
    - (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]];
  2. @JFK JFK renamed this gist Oct 10, 2012. 1 changed file with 12 additions and 24 deletions.
    36 changes: 12 additions & 24 deletions gistfile1.m → gistfile1.matlab
    Original file line number Diff line number Diff line change
    @@ -33,21 +33,17 @@ - (void)viewDidLoad

    NSMutableArray *dataForCellArray = [NSMutableArray array];
    for (int i = 0; i < 10; i++) {
    [dataForCellArray addObject:[NSString stringWithFormat:@"Cell
    Row %d", 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.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]];
    [self.sections addObject:[NSString stringWithFormat:@"dataForCellArray%d", i]];
    }
    }

    @@ -61,14 +57,12 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    return [self.sections count];
    }

    - (NSString *)tableView:(UITableView *)tableView
    titleForHeaderInSection:(NSInteger)section
    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
    {
    return [self.sections objectAtIndex:section];
    }

    - (NSInteger)tableView:(UITableView *)tableView
    numberOfRowsInSection:(NSInteger)section
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    if (section == 0) {
    return [dataForCellArray1 count];
    @@ -82,29 +76,23 @@ - (NSInteger)tableView:(UITableView *)tableView
    return 0;
    }

    - (UITableViewCell *)tableView:(UITableView *)tableView
    cellForRowAtIndexPath:(NSIndexPath *)indexPath
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView
    dequeueReusableCellWithIdentifier:CellIdentifier];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
    cell = [[[UITableViewCell alloc]
    initWithStyle:UITableViewCellStyleDefault
    reuseIdentifier:CellIdentifier] autorelease];
    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];
    cell.textLabel.text = [self.dataForCellArray3 objectAtIndex:indexPath.row];
    } else if (indexPath.section == 3) {
    cell.textLabel.text = [self.dataForCellArray4
    objectAtIndex:indexPath.row];
    cell.textLabel.text = [self.dataForCellArray4 objectAtIndex:indexPath.row];
    }
    return cell;
    }

    @end
    @end
  3. CodeIQ created this gist Oct 9, 2012.
    110 changes: 110 additions & 0 deletions gistfile1.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,110 @@
    //
    // MemoryLeakTestTableViewController.m
    // MemoryLeakTest

    @interface MemoryLeakTestTableViewController ()
    {
    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