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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:39:34+00:00 2026-06-01T04:39:34+00:00

I have a problem with leaking custom cells. In my overridden UITableViewController, I have,

  • 0

I have a problem with leaking custom cells.

In my overridden UITableViewController, I have,

- (UITableViewCell *)tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     TwitterTweetTableCell *cell = nil;

     // Obtain the cell...

    cell = [[TwitterTweetTableCell alloc]
            initWithTable:tableView
                andTweet:[[self getTimeline] objectAtIndex:indexPath.row]];

    return [cell autorelease];
}

And in the corresponding overridden UITableViewCell class,

- (TwitterTweetTableCell *) initWithTable:(UITableView *) tableView
    andTweet:(NSDictionary *) tweet
{

    tweetCell = nil;

    // ************************************************************************************
    // The identifier used in the following dequeue is the one set in the corresponding nib
    // ************************************************************************************

    tweetCell = (TwitterTweetTableCell *)
        [tableView dequeueReusableCellWithIdentifier:@"tweetCell"]; // <-- set this in NIB

    if (tweetCell)
    {
        NSLog(@"tweetCell: Reuse!");
    }

    if(!tweetCell)
    {
        NSArray *topLevelObjects = [[NSBundle mainBundle]
                loadNibNamed:@"TwitterTweetTableCell" owner:nil options:nil];

        for(id currentObject in topLevelObjects)
        {
            if([currentObject isKindOfClass:[TwitterTweetTableCell class]])
            {
                tweetCell = (TwitterTweetTableCell *)currentObject;

                break;
            }
        }

        // yadda, yadda, yadda

        [tweetCell retain];
    }

    return tweetCell;
}

There is a corresponding NIB for the custom cell (TwitterTweetTableCell), and as noted in the code, the Identifier for the cell is set to ‘tweetCell’ in there.

The code works fine except, according to Instruments, it leaks cells 🙁

I believe I’m correct in returning the cell with a retainCount of 1 (it’s a return from an alloc and, anyway, if I don’t it crashes with a zombie). As the code shows, I then autorelease it before finally handing it off to the table controller.

Thoughts on why this leaks would be appreciated.

  • 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-06-01T04:39:35+00:00Added an answer on June 1, 2026 at 4:39 am

    The problem here is that in cellForRowAtIndexPath: you are allocating memory for a new instance of your custom cell, but in the initializer for your custom cell, you never actually use that memory you allocate, since you don’t return self, and instead return a reusable existing cell or instantiate a new one from a nib.

    Since you’re initWithTable:andTweet: method isn’t really an initializer, you should just change it to being a convenience method that returns autoreleased instances instead. Change the method signature,

    + (TwitterTweetTableCell *) cellWithTable:(UITableView *) tableView
    andTweet:(NSDictionary *) tweet
    

    make it autorelease its return value,

    return [tweetCell autorelease];
    

    and then make a slightly different call to it in cellForRowAtIndexPath: and you’ll be all set:

    return [TwitterTweetTableCell cellWithTable:tableView
                                       andTweet:[[self getTimeline] objectAtIndex:indexPath.row]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a tableview with youtube videos embedded inside of the custom cells.
im new with objective-c. I have problem with memory leaking when developing iphone app.
i have small problem understanding why my smart pointer class is leaking on self
I have problem with the following code leaking memory... @property (nonatomic, retain) NSMutableArray *childrensArray;
I have problem in some JavaScript that I am writing where the Switch statement
I have problem with return statment >.< I want to store all magazine names
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have problem with ActionLink. I'd like to pass to my ActionLink parameter for
I have problem when I try insert some data to Informix TEXT column via

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.