Graphics Programs Reference
In-Depth Information
@end
In TouchDrawView.m , set every completed line's containingArray property in
endTouches: .
- (void)endTouches:(NSSet *)touches
{
for (UITouch *t in touches) {
NSValue *key = [NSValue valueWithNonretainedObject:t];
Line *line = [linesInProcess objectForKey:key];
if (line) {
[completeLines addObject:line];
[linesInProcess removeObjectForKey:key];
[line setContainingArray:completeLines];
}
}
[self setNeedsDisplay];
}
Finally, in clearAll of TouchDrawView.m , comment out the code that removes all
of the objects from the completeLines and create a new instance of NSMutableAr-
ray instead.
- (void)clearAll
{
[linesInProcess removeAllObjects];
// [completeLines removeAllObjects];
completeLines = [[NSMutableArray alloc] init];
[self setNeedsDisplay];
}
Build and profile the application. Choose Leaks as the instrument to use.
Draw a few lines and then double tap the screen to clear it. Select the Leaks instrument
from the top left table and wait a few seconds. Three items will appear in the summary
table: an NSMutableArray , a few Line instances, and a Malloc 16 Bytes block. This
memory has been leaked.
Select the Leaks pop-up button in the breadcrumb bar and change it to Cycles & Roots
( Figure 21.19 ) . This view gives you a lovely graphical representation of the retain cycle:
an NSMutableArray (our completeLines array) has a reference to a list of Line s,
and each Line has a reference back to its containingArray .
Figure 21.19 Cycles and Roots
 
Search WWH ::




Custom Search