Release understanding help…
Release understanding help…
- Subject: Release understanding help…
- From: Mark Dawson <email@hidden>
- Date: Mon, 6 Dec 2004 17:35:21 -0800
Another set of newbie questions…
I've created a new custom formatter using found code pieces
(1) When I try to do a release on the "validChars", I get a crash (msg_objc). Shouldn't I be releasing it? I DID create it with an alloc…
(2) The "validChars = [validChars " is obviously valid Obj-C, but I'm not sure "where" the original string goes, as it isn't mutable. Does the compiler take care of destroying the old string, or is my problem that the assignment creates a string that doesn't have to be released (because it returns a static value or autoreleased?), but leaks the original string?
(3) disallowedCharacters also doesn't have to be released because its getting a static value or autoreleased
?
Thanks!
- (BOOL)isPartialStringValid:(NSString *)partialString
newEditingString:(NSString **)newString errorDescription:(NSString **)error
{
NSRange foundRange;
// allow numbers, decimal point, ", ', m, c
NSString* validChars = [[NSString alloc] initWithString: @"0123456789mc/'\" "];
validChars = [validChars stringByAppendingString:[[NSUserDefaults standardUserDefaults] objectForKey:NSDecimalSeparator]];
NSCharacterSet *disallowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:validChars] invertedSet];
foundRange = [partialString rangeOfCharacterFromSet:disallowedCharacters];
if(foundRange.location != NSNotFound)
{
*error = @"Illegal characters found in input";
NSBeep();
NO);
}
if ([partialString length] > 0)
*newString = partialString;
#if 0
[validChars release];
[disallowedCharacters release];
#endif
YES);
}
_______________________________________________
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