Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView memory leak with imageWithContentsOfFile
    primarykey
    data
    text
    <p>I am leaking memory in my <code>UITableView</code> for a standard image/text view. I am loading an image with <code>imageWithContentsOfFile</code> and assigning it to my <code>cell</code>'s <code>imageView.image</code>. </p> <p>This image does not get released automatically, I had to iterate the cells in the <code>-dealloc</code> method and set it to 0. </p> <p>But I am still loosing memory each time I am showing my <code>UITableView</code> and I am really do not know why. I also removed the <code>autorelease</code> from cell and tried to release it manually, but I am still loosing memory.</p> <p>Alex</p> <pre><code>- (id) initWithProfils:(ColorPainterProfiles*) profils listener:(NSObject&lt;ColorPainterTableListener&gt;*) listener{ self = [super init]; if (self) { _listener=listener; _profils=profils; } return self; } - (void)dealloc { for (int section = 0; section &lt; [self.tableView numberOfSections]; section++) { for (int row = 0; row &lt; [self.tableView numberOfRowsInSection:section]; row++) { NSIndexPath* cellPath = [NSIndexPath indexPathForRow:row inSection:section]; UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:cellPath]; cell.imageView.image=0; //[cell release]; } } [super dealloc]; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } #pragma mark - View lifecycle - (void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } // Implement loadView to create a view hierarchy programmatically, without using a nib. - (void)loadView { //((UILabel*)self.navigationItem.titleView).text=NSLocalizedString(@"Change Picture", @""); } - (void) setTableView:(UITableView *)tableView { [super setTableView:tableView]; self.tableView.delegate=self; self.tableView.dataSource=self; if ([LibTools isIPad]) { self.tableView.rowHeight=self.tableView.rowHeight*3; } else { self.tableView.rowHeight=self.tableView.rowHeight*2; } } - (void)viewDidUnload { [super viewDidUnload]; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { // If row is deleted, remove it from the list. if (editingStyle == UITableViewCellEditingStyleDelete) { // delete your data item here [_profils deleteAt:[_profils.profils objectAtIndex:indexPath.row]]; [_profils removeProfileAt:indexPath.row]; // Animate the deletion from the table. [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [_listener actionColorPainterTable:[_profils.profils objectAtIndex:indexPath.row] sender:self]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // There is only one section. return 1; } - (NSInteger) numberOfRows { return _profils.profils.count; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self numberOfRows]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *MyIdentifier = @"ManageModels"; // Try to retrieve from the table view a now-unused cell with the given identifier. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; // If no cell is available, create a new one using the given identifier. if (cell == nil) { // Use the default cell style. cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease]; } else { cell.imageView.image=0; } ColorPainterProfile *cpp=[_profils.profils objectAtIndex:indexPath.row]; cell.textLabel.text=cpp.title; NSString *path=[LibTools documentsSubFolder:cpp._subFolder]; cell.imageView.image =[UIImage imageWithContentsOfFile:[path stringByAppendingPathComponent:cpp._imageName]]; //cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator; // Set up the cell. //cell.textLabel.textColor=[UIColor grayColor]; return cell; } /*- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)sec { return @"Hello"; }*/ /*- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath { return nil; }*/ - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload