Re: Some really simple release/autoRlease questions
Re: Some really simple release/autoRlease questions
- Subject: Re: Some really simple release/autoRlease questions
- From: "John C. Randolph" <email@hidden>
- Date: Sat, 15 Mar 2003 14:42:57 -0800
On Saturday, March 15, 2003, at 02:17 PM, Krevnik wrote:
On Saturday, March 15, 2003, at 02:05 PM, Jeffrey Mattox wrote:
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?
Yes, and it is the normal behavior of all of Apple's class methods
that do that. 3rd Party classes may behave differently, but they
shouldn't.
Umm, +alloc is a class method, and it returns an object that is *not*
autoreleased. Methods like +stringWithFoo: or +dictionaryWithBar: are
known as "convenience constructors", and they all return autoreleased
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:
If memory is your priority, I would take this route... but if you need
speed, that is going to be slow as snot on a loop that iterates
thousands of times. The best (IMO) for a speedy loop is to create
objects in an autoreleased state and ignore the deallocation. That way
the cycles needed to collect the memory from them is used during the
run loop, rather than your tight loop.
Another tactic that might be worth trying is to use mutable strings,
and re-use them in your loop.
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?
I honestly don't know this one.
ObjectAlloc has a lot of options about what to show you. Try them.
-jcr
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
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.