• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: retainCount
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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>)

  • Prev by Date: Image Scaling Code
  • Next by Date: Re: Image Scaling Code
  • Previous by thread: Re: retainCount
  • Next by thread: Can't Use java.io.FileInputStream Within Cocoa
  • Index(es):
    • Date
    • Thread