This is my first post here, just started with Cocoa few days ago. There are
few ObjectiveC concepts that confuse me now and I think similar code is
going to confuse me even more in the future.
Here is the code from a Cocoa book and I want to know if this is a memory leak?
fileName = [fileName stringByStandardizingPath];
Documentation for stringByStandardizingPath:
Return Value - A new string made by removing extraneous path
components from the receiver. .. If any other kind of error is encountered
(such as a path component not existing), self is returned.
How am I supposed to handle that? Should I release fileName? Should I
compare old and new pointers? Maybe I should code like this:
What if original string was created from string literal, like:
NSString *fileName = @"~/SomeFile.txt";
My background is in straight C where things look a bit more straightforward
than these oo concepts.
few ObjectiveC concepts that confuse me now and I think similar code is
going to confuse me even more in the future.
Here is the code from a Cocoa book and I want to know if this is a memory leak?
fileName = [fileName stringByStandardizingPath];
Documentation for stringByStandardizingPath:
Return Value - A new string made by removing extraneous path
components from the receiver. .. If any other kind of error is encountered
(such as a path component not existing), self is returned.
How am I supposed to handle that? Should I release fileName? Should I
compare old and new pointers? Maybe I should code like this:
Code:
- (NSString *)standardizePath:(NSString *)origFileName
{
NSString *newFileName = [origFileName stringByStandardizingPath];
if (origFileName != newFileName)
[origFileName release];
return (newFileName);
}
What if original string was created from string literal, like:
NSString *fileName = @"~/SomeFile.txt";
My background is in straight C where things look a bit more straightforward
than these oo concepts.