Some really simple release/autoRlease questions
Some really simple release/autoRlease questions
- Subject: Some really simple release/autoRlease questions
- From: Jeffrey Mattox <email@hidden>
- Date: Sat, 15 Mar 2003 16:05:29 -0600
If I do this, theDictionary gets a retainCount of 1.:
NSMutableDictionary *theDictionary =
[NSMutableDictionary dictionaryWithCapacity:1];
1. Is it in the autoRelease pool? Is that the case with all class
methods that create and return objects?
2. If I have a big loop that uses an NSString in the loop, is it
considered good form (to conserve memory) to use alloc/init and then
release the string from the previous loop, thusly:
NSString *theString = nil;
while (...) {
...
if ( theString ) {
[theString release];
}
theString = [[NSString alloc] initWithFormat:...];
[anArray addObject:theString]; // retains theString
}
if ( theString ) {
[theString release];
}
as opposed to:
NSString *theString;
while (...) {
...
theString = [NSString stringWithFormat:...];
[anArray addObject:theString];
}
or
while (...) {
...
[anArray addObject:[NSString stringWithFormat:...]];
}
3. I've looked as the utility ObjectAlloc, but it generates an
unwieldy output. Is that the best way to find leaks due to objects I
explicitly create? Is there a way to reduce the clutter?
Jeff
_______________________________________________
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.