Re: retainCount
Re: retainCount
- Subject: Re: retainCount
- From: Vince DeMarco <email@hidden>
- Date: Fri, 13 Jul 2001 20:46:00 -0700
On Friday, July 13, 2001, at 04:09 PM, Markus Hitter wrote:
>
Hello,
>
>
here's a code fragment ripped out of a small app which gives me a
>
signal 10 (SIGBUS):
>
>
@implementation Worker
>
[...]
>
NSString *intImageName;
>
[...]
>
- (void)awakeFromNib {
>
intImageName = [[NSString alloc] initWithString:@"temp-image-"];
>
intImageName = [intImageName stringByAppendingString:NSUserName()];
>
NSLog(@"intImageName's retain count is: %d", [intImageName
>
retainCount]);
>
[...]
>
stringByAppendingString: returns a new autorelease string.
change the method to
- (void)awakeFromNib
{
intImageName = [[NSString alloc] initWithFormat:@"temp-
image-%@",NSUserName()];
NSLog(@"intlImageName's retain count is: %d",[intImageName
retainCount]);
}
Be sure to have a dealloc method that releases intImageName
>
The last line gives the signal. Using %@ instead of %d makes no change.
>
Removing the NSLog line makes the code work fine.
>
>
Anybody knows what's the trouble with retainCount?
>
>
As you can guess, I try to verify my knowledge about retaining and
>
releasing. Is there some other chance to view retains / releases /
>
memory leaks?
Removing the NSLog made it work by luck, since in youre version, the
second intImageName is actually autoreleased and nobody is retaining it.
vince
References: | |
| >retainCount (From: Markus Hitter <email@hidden>) |