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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:24:53+00:00 2026-05-22T23:24:53+00:00

I would like to know how to correctly release a cell and fix a

  • 0

I would like to know how to correctly release a cell and fix a memory leak I have. and also ask if a memory leak can cause crashing on scrolling if the numbers cell numbers get high?

Here is my cell where the leak is coming from any suggestions?

NSString *identifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

if (cell == nil) {



}


//add subtitle
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
reuseIdentifier:@"cell"];




  /*
  //Here it adds a nice shadow to the table view but will crash on rotation and send a 
  wierd dump to ApplistViewController !!!???? 
  tableView.layer.shadowColor = [[UIColor blackColor] CGColor];
  tableView.layer.shadowOffset = CGSizeMake(1.0f, 1.0f);
  tableView.layer.shadowRadius = 8.0f;
  tableView.layer.shadowOpacity = 1.0f;     
  */


[cell.textLabel setNumberOfLines:1];
[cell.textLabel setText:[(Tweet*)[authors objectAtIndex:indexPath.row] author]];  

[cell.detailTextLabel setText:[(Tweet*)[tweets objectAtIndex:indexPath.row] tweet]];
[cell.detailTextLabel setNumberOfLines:10];
[cell.textLabel setTextColor:[UIColor darkGrayColor]];
[cell.textLabel setShadowColor:[UIColor whiteColor]];
[cell.textLabel setShadowOffset:CGSizeMake(0.5, 0.5)];
[cell.detailTextLabel setTextColor:[UIColor blackColor]];
//[cell.detailTextLabel setText:[(Tweet*)[retweetCount objectAtIndex:indexPath.row] 
reTweetCount]];
[cell.textLabel setUserInteractionEnabled:YES];
[cell.contentView setMultipleTouchEnabled:YES];
// cell.text = [[NSString alloc] initWithFormat:@"Cell :%i", indexPath.row];    





 NSURL *url = [NSURL URLWithString:[(Tweet*)[avatarsURL 
 objectAtIndex:indexPath.row]avatarURL]];
 NSData *data = [NSData dataWithContentsOfURL:url];
 // NSLog(@"http://a0.twimg.com/profile_images/1268205919/iDD_normal.png");  
 UIImage *tableImage = [[UIImage alloc] initWithData:data]; 
 [cell.imageView setImage:tableImage]; 
 cell.imageView.image = tableImage ;
 CGSize imageSize = CGSizeMake(45,45);  
 UIGraphicsBeginImageContext(imageSize); 
 CGRect imageRect = CGRectMake(0.2, 0.1, imageSize.width, imageSize.height); 
 [tableImage drawInRect:imageRect]; 
 cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext(); 
 UIGraphicsEndImageContext();    







//PlaceMent avatars! would like to use a if statment to place this image in the cell if 
before it retrives the avatar just like the method above for the profile!

/*
 NSString *avatar = [[NSBundle mainBundle] pathForResource:@"avatar" ofType:@"png"];
 UIImage *setAvatar = [[UIImage alloc] initWithContentsOfFile:avatar];

 //now place avatar in cell
 cell.imageView.image = setAvatar;
 */    

 //add gradient to cell 
 UIImage *gradient = [UIImage imageNamed:@"gradientcell2.png"];
 UIImageView *cellimage = [[UIImageView alloc] initWithImage:gradient];
 cellimage.contentMode = UIViewContentModeScaleToFill;
 cell.backgroundView = cellimage;


  [cellimage release];      



UIImage *selectedGradient = [UIImage imageNamed:@"selectedcell.png"];

UIImageView *selectedCell = [[UIImageView alloc] initWithImage:selectedGradient];
selectedCell.contentMode = UIViewContentModeScaleToFill;
cell.selectedBackgroundView = selectedCell;    

//subtitle if needed !! Also change UITableViewStlyle from default to Subtitle up 7 
lines
// cell.detailTextLabel.text = @"subtile";



//yeah another warning within the tableview whats new =P
[tableView setBackgroundColor:[UIColor clearColor]];     


return cell;


[cell autorelease];
}

ALL the LEAKS are fixed!!!! Thank You but why do I crash when I add a count integer ?

Any Suggestions?

2011-06-01 18:24:55.663 ThemeCatcher[4641:207] *** Terminating app due to uncaught    
exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 16 
beyond bounds [0 .. 15]'
*** Call stack at first throw:
(
0   CoreFoundation                      0x014dcbe9 __exceptionPreprocess + 185
1   libobjc.A.dylib                     0x016315c2 objc_exception_throw + 47
2   CoreFoundation                      0x014d26e5 -[__NSArrayM objectAtIndex:] +  
261
3   ThemeCatcher                        0x00025833 -[TwitterVeiwController 
tableView:cellForRowAtIndexPath:] + 531
4   UIKit                               0x007bb7fa -
[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 634
5   UIKit                               0x007b177f -
[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75
6   UIKit                               0x007c6450 -
[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561
7   UIKit                               0x007be538 -[UITableView layoutSubviews] + 
242
8   QuartzCore                          0x00460451 -[CALayer layoutSublayers] + 181
9   QuartzCore                          0x0046017c CALayerLayoutIfNeeded + 220
10  QuartzCore                          0x0045937c 
_ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
11  QuartzCore                          0x004590d0 _ZN2CA11Transaction6commitEv +   
292
12  QuartzCore                          0x004897d5 
_ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
13  CoreFoundation                      0x014bdfbb 
__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
14  CoreFoundation                      0x014530e7 __CFRunLoopDoObservers + 295
15  CoreFoundation                      0x0141bbd7 __CFRunLoopRun + 1575
16  CoreFoundation                      0x0141b240 CFRunLoopRunSpecific + 208
17  CoreFoundation                      0x0141b161 CFRunLoopRunInMode + 97
18  GraphicsServices                    0x01efa268 GSEventRunModal + 217
19  GraphicsServices                    0x01efa32d GSEventRun + 115
20  UIKit                               0x0075642e UIApplicationMain + 1160
21  ThemeCatcher                        0x000021c9 main + 121
22  ThemeCatcher                        0x00002145 start + 53
23  ???                                 0x00000001 0x0 + 1

)

terminate called after throwing an instance of 'NSException'
Current language:  auto; currently objective-c
(gdb) 
  • 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-22T23:24:54+00:00Added an answer on May 22, 2026 at 11:24 pm
    1. cell object needs to be autoreleased here – cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
      reuseIdentifier:@"cell"];
      and this line needs to be inside if ( cell == nil ) { //here }.
    2. You alloc-init tableImage but do not release it.
    3. selectedCell is not released either.
    4. You are autoreleaseing after returning from the method. This won’t happen and in case of reusable cell, it will send an additional release message crashing your app.

    There seem to more issues within your comments which I have chosen not to include. Try using the Leaks application to check for memory leaks.

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

Sidebar

Related Questions

I would like to know if I can open 2 different diagrams using MS
Our customer would like to know who is online and currently using the custom
I would like to know which dependency described in my pom.xml brings a transitive
I would like to know what semaphores, messageQueues, etc... are active in my vxWorks
I would like to know what kind of tool you use for writing your
I would like to know what's the best technique to do single sign-on in
I would like to know what would be the best way to do unit
I would like to know if there is any way to add custom behaviour
I would like to know your experience when you need to take over somebody
I would like to know and understand the steps involved in fetching mail from

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.