Re: NSDictionary, allKeys and the NSAutoreleasePool

2009-09-03 Thread Greg Parker
On Sep 3, 2009, at 11:47 AM, Jens Alfke wrote: On Sep 3, 2009, at 11:40 AM, Scott Andrew wrote: I could have sworn in either the apple docs (or one of the cocoa books, maybe this board). I maybe thinking of the general rule that you don't own the object until you retain it and its only valid

Re: NSDictionary, allKeys and the NSAutoreleasePool

2009-09-03 Thread Jens Alfke
On Sep 3, 2009, at 11:40 AM, Scott Andrew wrote: I could have sworn in either the apple docs (or one of the cocoa books, maybe this board). I maybe thinking of the general rule that you don't own the object until you retain it and its only valid or the within the method that its recieved.

Re: NSDictionary, allKeys and the NSAutoreleasePool

2009-09-03 Thread Scott Andrew
I could have sworn in either the apple docs (or one of the cocoa books, maybe this board). I maybe thinking of the general rule that you don't own the object until you retain it and its only valid or the within the method that its recieved. My bad. Scott On Sep 3, 2009, at 11:29 AM, mmalc

Re: NSDictionary, allKeys and the NSAutoreleasePool

2009-09-03 Thread mmalc Crawford
On Sep 3, 2009, at 7:56 AM, Scott Andrew wrote: As Cocoa documentation states all items returned from a message are autoreleased unless otherwise stated in the documentation for the API call. The documentation emphatically does not state that. The basic rules are given here:

Re: NSDictionary, allKeys and the NSAutoreleasePool

2009-09-03 Thread David Duncan
This is essentially correct. Why bother to decrement the retain count when the object is going away after all... On Sep 3, 2009, at 7:29 AM, Graham Cox wrote: Relying on retain counts to tell you an object's state is not a good idea. What I'm guessing is that the code internally looks someth

Re: NSDictionary, allKeys and the NSAutoreleasePool

2009-09-03 Thread Greg Guerin
Horst Jäger wrote: NSDictionary *di = [[NSDictionary alloc] init]; NSArray *ar = [di allKeys]; di is an empty NSDictionary. Therefore, ar will always be an empty immutable NSArray. Consequently, it's possible to return a singleton empty NSArray that's never released. I'm not saying thi

Re: NSDictionary, allKeys and the NSAutoreleasePool

2009-09-03 Thread Scott Andrew
"ar" is not a member of "d"i. allKeys creates an autoreleased NSArray with the keys values retained in indexes. "ar" is placed in the auto release pool when it is created in the allKeys call. When you call [autorelease release] the items are freed when you since the pool is released and fre

Re: NSDictionary, allKeys and the NSAutoreleasePool

2009-09-03 Thread Graham Cox
On 04/09/2009, at 12:21 AM, Horst Jäger wrote: Any explanation? Relying on retain counts to tell you an object's state is not a good idea. What I'm guessing is that the code internally looks something along the lines of: - (void) release { if( retainCount == 1 ) [self deallo

Re: NSDictionary, allKeys and the NSAutoreleasePool

2009-09-03 Thread Roland King
Is that *all* the code? Your output has two 'ar 1' lines but you only NSLog() with that pattern once. The output doesn't match the code. On 03-Sep-2009, at 10:21 PM, Horst Jäger wrote: Hi, yesterday I stumbled upon something strange concerning the autorelease pool. Please consinder the

NSDictionary, allKeys and the NSAutoreleasePool

2009-09-03 Thread Horst Jäger
Hi, yesterday I stumbled upon something strange concerning the autorelease pool. Please consinder the following lines of code: NSLog(@"devel"); NSAutoreleasePool *autoreleasePool = [[NSAutoreleasePool alloc] init]; NSDictionary *di = [[NSDict