Not Sure of Memory Leak with ** ?
Not Sure of Memory Leak with ** ?
- Subject: Not Sure of Memory Leak with ** ?
- From: Craig Bakalian <email@hidden>
- Date: Sat, 20 Nov 2004 06:46:41 -0500
Hi,
This is the first time I have made a function call like this, with a pointer to a pointer -
-(
BOOL)isWordInQuestion: (NSString *)word location: (NSString **)location
{
NSRange r = NSMakeRange(
0);
NSMutableString *ms = [NSMutableString string];
[ms appendString: [
self stringFromRTFDData: [
self questionBody]]];
[ms appendString: [
self stringFromRTFDData: [
self optionOne]]];
[ms appendString: [
self stringFromRTFDData: [
self optionTwo]]];
[ms appendString: [
self stringFromRTFDData: [
self optionThree]]];
[ms appendString: [
self stringFromRTFDData: [
self optionFour]]];
NS_DURING
r = [ms rangeOfString: word];
NS_HANDLER
if ([[localException name] isEqualToString: NSInvalidArgumentException] ||
[[localException name] isEqualToString: NSRangeException])
{
return NO;
}
NS_ENDHANDLER
if(r.location >
0 && r.length >
0)
{
NSMutableString *s = [NSMutableString string];
[s appendString: [[
self test]testName]];
[s appendString:
@", "];
[s appendString: [
self getQuestionNameAndNumber]];
*location = [s copy];
return YES;
}
else return NO;
}
And then another object iterates through all of the above objects and calls the above function like so -
- (
id)sender
{
NSString *word = [findWordTextField stringValue];
if(![word isEqualToString:
@""])
{
0;i<[allQuestions count]; i++)
{
Question *q = [allQuestions objectAtIndex: i];
BOOL isIn;
NSString *loc =
nil;
isIn = [q isWordInQuestion: word location: &loc];
@"%@", loc);
[loc release];
}
}
}
The big questions is - am I releasing properly, is there any leaking? I have tested, not thoroughly, but still I am concerned. I am not throwing and memory erros, but... How does one release, retain, copy, when using a point to a pointer in Foundation and Objective C?
Craig Bakalian
www.eThinkingCap.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