Another memory question
Another memory question
- Subject: Another memory question
- From: James Ludtke <email@hidden>
- Date: Tue, 26 Aug 2003 14:53:54 -0400
In the code fragment below I reassign a new value to an
NSString. (I have seen others do that as well.)
- (void)awakeFromNib {
NSString *demoFile;
demoFile = [NSString stringWithString: @"~/Application User
Data/dsf.plist"];
demoFile = [demoFile stringByExpandingTildeInPath];
// more code
}
If I have understood it correctly, the second assignment creates
a new memory block for the string, and the first string is still
in memory, but can no longer be accessed.
My questions are:
1) Will the auto release process release the first block or
will there be a memory leak?
2) Is the above example good practice, or would the following
have been better:
- (void)awakeFromNib {
NSString *demoFile;
NSString *temp = [[NSString alloc] init];
temp = [NSString stringWithString: @"~/Application User Data/dsf.plist"];
demoFile = [temp stringByExpandingTildeInPath];
[demoFile release];
// more code
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.