Re: Autorelease pool questions
Re: Autorelease pool questions
- Subject: Re: Autorelease pool questions
- From: "Sven A. Schmidt" <email@hidden>
- Date: Thu, 23 Jan 2003 00:23:36 +0100
I think what Rakesh meant was
NSString *s1 = [[NSString alloc] init];
NSString *s2 = [[NSString alloc] initWithString:@"Rakesh"];
NSString *s3 = [NSString alloc];
NSLog( @"s1: %x %i", [s1 retainCount], [s1 retainCount] );
NSLog( @"s2: %x %i", [s2 retainCount], [s2 retainCount] );
NSLog( @"s3: %x", [s3 retainCount], [s3 retainCount] );
and that really prints
2003-01-22 22:50:39.664 test[18029] s1: 7fffffff 2147483647
2003-01-22 22:50:39.665 test[18029] s2: 1 1
2003-01-22 22:50:39.665 test[18029] s3: ffffffff
I added 's3' out of curiosity, because I was also suspecting something
uninitialized. I thought that maybe 'empty' objects from 'init' without
data might not be fully initialized in class clusters until they are
assigned something.
NSObject on the other hand prints the expected:
2003-01-22 22:50:39.666 test[18029] o1: 1
2003-01-22 22:50:39.666 test[18029] o2: 1
and NSArray, another class cluster behaves the same:
id a1 = [[NSArray alloc] init];
id a2 = [[NSArray alloc] initWithObjects: s1, s2, s3, nil];
id a3 = [NSArray alloc];
NSLog( @"a1: %d", [a1 retainCount] );
NSLog( @"a2: %d", [a2 retainCount] );
NSLog( @"a3: %d", [a3 retainCount] );
2003-01-22 22:50:39.667 test[18029] a1: 1
2003-01-22 22:50:39.667 test[18029] a2: 1
2003-01-22 22:50:39.667 test[18029] a3: 1
Sven
On Montag, Januar 20, 2003, at 03:09 Uhr, j o a r wrote:
I very much doubt that this code even compiles... You need to read and
fix the warnings that you get when you compile! Programming is a
precision art - you need to be careful with what you write, every
single character counts!
NSString *myString = [[NSSTring alloc] init];
This should of course read: [[NSString alloc] init], but I asume it's
a typo you did when transfering the code over to Mail?
NSString *myString1 = [[NSString initWithString:@"Rakesh"];
In this case you haven't balanced the parenthesis, but even if we
disregard that typo it remains that you cannot - cannot - send an init
message to the NSString class object, only to a newly created instance
(read the Obj-C PDF to learn about the difference between class- and
instance methods). That must have resulted in warnings?
Now back to your printed logs. I'm surprised that myString gives you
trouble, I would have expected it to be the other way around since the
strange large number printed for that variable looks like it's the
result of printing a non-initialized value - like I would have
expected the myString1 to be.
j o a r
On Sunday, Jan 19, 2003, at 21:08 Europe/Stockholm, Rakesh Pandey
wrote:
In my code I create two NSString object like this:
NSString *myString = [[NSSTring alloc] init];
NSString *myString1 = [[NSString initWithString:@"Rakesh"];
Now I tryt to priont the retain count
NSLog(@"The retainCount for myString = %d \n And thats of myString1 =
%d",
[myString retainCount], [myString1 retainCount];
And the results is:
The retainCount for myString = 2147483647
And thats of myString1 = 1
I could not understand why is it so ?
_______________________________________________
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.
_______________________________________________
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.