• 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
Release understanding help…
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Release understanding help…
      • From: Sherm Pendley <email@hidden>
    • Re: Release understanding help…
      • From: Byron Wright <email@hidden>
  • Prev by Date: Re: Which class methods return autoreleased objects?
  • Next by Date: Re: Retriving the tag of superMenu Items
  • Previous by thread: Flogging a dead horse (was isa swapping, resknife sources, interf ace builder crashing)
  • Next by thread: Re: Release understanding help…
  • Index(es):
    • Date
    • Thread