Alloc - add as accessoryView - release: does it leak?
Does this leak memory? This code is executed in cellForRowAtIndexPath:
outside the cell creation block (so each time the table cell is updated).
MyView *myView = [[MyView alloc] init];
// ... configuration code
cell.accessoryView = myView;
[myView release];
Or in other words, will the UITableViewCell
release the object in its accessoryView
when a new object gets assigned to it?
Than开发者_C百科ks.
Yes, the cell will release the accessory view and you do not have a leak in the example.
The property accessoryView
of a UITableViewCell
is a retain
type, in common with many view properties in the kit. Check the Apple documentation for UITableViewCell
to convince yourself of this. Therefore there will be no leak in your example - the retain count has been correctly managed. You've also correctly released after setting the accessory view, on account of your alloc
call.
精彩评论