Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView - moveRowAtIndexPath causes memory leak
    primarykey
    data
    text
    <p><strong>Overview</strong></p> <ul> <li>In an iOS project, I have a <code>UITableView</code> and I am trying to move a row of the UITableView. </li> <li>In my model, the order of data has been changed, so I am trying to visually show it in the table, that is why I have used <code>UITableView</code>'s method <code>moveRowAtIndexPath:toIndexPath:</code></li> <li>In order to do so I have created an <code>NSIndexPath</code> instance which I am passing to the UITableView's method.</li> </ul> <p><strong>When the leak accurs</strong> </p> <ul> <li>When you create an NSIndexPath instance using the method <code>indexPathForRow: section:</code> (as shown in the code section) and then pass it to the <code>UITableView</code>'s method <code>moveRowAtIndexPath: toIndexPath:</code> it leaks.</li> </ul> <p><strong>Note:</strong></p> <ul> <li>I am using ARC (automatic reference counting)</li> <li>XCode 4.3.1</li> <li>I used the Instruments (Xcode menu - Product > Profile) to determine the memory leak</li> </ul> <p><strong>Code: (inside UITableViewController)</strong></p> <pre><code>NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:newRow inSection:0]; //leaking [self.tableView beginUpdates]; [self.tableView moveRowAtIndexPath:originalIndexPath toIndexPath:newIndexPath]; //I think this causes the leak [self.tableView endUpdates]; </code></pre> <p><strong>Steps I have tried</strong></p> <ul> <li>Commenting out the call to the method <code>moveRowAtIndexPath:originalIndexPath toIndexPath:</code>, prevents the memory leak</li> <li><p>I have manually used <code>CFRelease</code> (not sure this is a good practice in an Automatic Reference Counting environment)</p> <p><strong>CFRelease((__bridge void *)toIndexPath);</strong></p></li> </ul> <p><strong>Questions:</strong></p> <ul> <li>Why does this occur ? is there any solution to it ?</li> <li>Is instrument's memory leak results accurate ?</li> <li>Is there a bug in UITableView's method <code>moveRowAtIndexPath:originalIndexPath toIndexPath:</code> ?</li> <li>Is CFRelease an option ? Is there a safe way to prevent the app from crashing in case CFRelease tries to release a memory that has been already released (see exact code above).</li> </ul>
    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