[futurebasic] Re: [FB] CFStrings and Paths

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2011 : Group Archive : Group : All Groups

From: Brian S <fblistserve@...>
Date: Tue, 28 Jun 2011 15:02:52 -0700
btw: writing this code in FB introduces a situation that wouldn’t typically come up in a Cocoa program linked with AppKit.
On Jun 28, 2011, at 12:31 PM, Brian S wrote:
>  NSString *outString = [(NSString *)s stringByExpandingTildeInPath];

The NSString class method stringByExpandingTildeInPath is a convenience function that creates a string that is automatically added to the autorelease pool ( meaning the string will be released when the pool is drained ). In Cocoa all apps using AppKit ( which is most ) automatically allocate an autorelease pool, so the programmer does not own outString and does not ( and should not ) release it; It is handled automatically.

> CFRelease( result )
So why the CFRelease of the string? Well, since there is no autorelease pool in this snippet the string leaks memory. A better way to write it would be to create an autorelease pool, not do the release and do the pool drain. Looks like Deep might have done just that in his code. 

Brian S