I’m having a problem setting a passed pointer to nil. When I run the following code through GDB I see that the passed variable “string” is locally set to nil within the called function, but in the scope where it is called it is still pointing to the original memory address. I figure the solution to this problem will involve a combo of reference and dereference operators, I am just not good enough at the fundamentals to figure this one out 🙂
#import "AppDelegate.h"
@interface AppDelegate()
+(void)releaseAndNullify:(id)input;
@end
@implementation AppDelegate
@synthesize window;
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString *string = [NSString string];
[AppDelegate releaseAndNullify:string];
}
+(void)releaseAndNullify:(id)input
{
if (input)
{
[input release];
input = nil;
}
}
-(void)dealloc
{
[window release];
[super dealloc];
}
@end
Here is the fix I found from another post: