• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Question about Outline View code in Documentation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: Question about Outline View code in Documentation (From: James McConnell <email@hidden>)
 >Re: Question about Outline View code in Documentation (From: mmalcolm crawford <email@hidden>)

  • Prev by Date: Re: are there any custom IB Palettes?
  • Next by Date: colored text in an NSTextView
  • Previous by thread: Re: Question about Outline View code in Documentation
  • Next by thread: NSColor Deadlock bug?
  • Index(es):
    • Date
    • Thread