Re: Question about Outline View code in Documentation
Re: Question about Outline View code in Documentation
- Subject: Re: Question about Outline View code in Documentation
- From: mmalcolm crawford <email@hidden>
- Date: Sat, 7 Feb 2004 03:41:34 -0800
On Feb 6, 2004, at 8:31 PM, mmalcolm crawford wrote:
- (NSArray *)children {
if (children == NULL) {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *fullPath = [self fullPath];
BOOL isDir, valid = [fileManager fileExistsAtPath:fullPath
isDirectory:&isDir];
if (valid && isDir) {
NSArray *array = [fileManager
directoryContentsAtPath:fullPath];
int cnt, numChildren = [array count];
children = [[NSMutableArray alloc]
initWithCapacity:numChildren];
for (cnt = 0; cnt < numChildren; cnt++) {
NSString *path = [array objectAtIndex:cnt];
if (![path hasPrefix:@"."])
{
[children addObject:[[FileSystemItem alloc] initWithPath:path
parent:self]];
}
}
} else {
children = IsALeafNode;
}
}
return children;
}
Since offlist someone, quite rightly, drew my attention to the memory
management "issues" in this method, I should note the comments made at
the top of the original sample file:
"This object can be improved a great deal; it never frees nodes that
are expanded; it also
is not too lazy when it comes to computing the children (when the
number of children
at a level are asked for, it computes the children array)."
Finding memory leaks in the code above, and in the full example, is
left as an exercise for the reader :-)
mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.