Re: Crash after weeks of doing nothing to my code
Re: Crash after weeks of doing nothing to my code
- Subject: Re: Crash after weeks of doing nothing to my code
- From: Nick Zitzmann <email@hidden>
- Date: Tue, 2 Aug 2005 20:24:50 -0600
On Aug 2, 2005, at 7:36 PM, Adam wrote:
Anyone have a clue?
Yes. Take a look at that for loop:
NSString *oneStringFromArray = [[NSString alloc] init];
Here you create a completely empty, immutable object. This isn't
necessary because you can't do much of anything with it. If for some
reason you want to make empty strings, then you should probably use
@"" instead.
oneStringFromArray = [arrayToStripNewLineCharFromString
objectAtIndex:i];
Here the program leaks memory, because you blew away the pointer to
the string you created one line before.
cookieString = [[NSString alloc] initWithFormat:@"(%d)",
cookie];
This isn't part of the problem, but here you're creating a string and
not releasing it, so it's another memory leak.
oneStringFromArray = [cookieString
stringByAppendingString:oneStringFromArray];
Here you overwrite the pointer again.
[oneStringFromArray release];
Here you double-release the object that was returned by -
stringByAppendingString: above. Since -stringByAppendingString:
returns an autoreleased object, this is the most likely cause of the
crash.
Nick Zitzmann
<http://www.chronosnet.com/>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden