I have had a look at all the comments and I am starting to see what I should be doing. To that end I have modified my code (see below) I have changed new
stringByAppendingPathComponent, hows it work?
Simple. You want to append a path component. You send that message to the string you want to append a path component to, passing the path component you want to append.
Path components are not the slashes; if they were, the pathComponents method would return nothing but an array of slashes. Path components are the parts between the slashes (although there is a special case, described in the definition of pathComponents).
The slash is the path separator. This is hard-coded inside of Cocoa; it's currently (and likely to always be) a slash. So, if you really wanted to append a slash to a string, the most likely reason would be that you want to append a path separator, not a path component.
[newPath setString:rootPath]; [newPath appendString:@"/"]; [newPath appendString:fileName];
fileName is the component you want to add. Use stringByAppendingPathComponent: and pass fileName, not a slash.
As for whether your example leaks: Well, does an object fall out of scope without getting released? The answer to that question is the answer to whether it's a leak. If you're not sure, review the memory management rules.