On Jul 15, 2011, at 12:38 PM, Kevin Muldoon wrote:

> while (fgets(buffer, sizeof(buffer), filePointer) != NULL) {
> 
>                       NSString *line = [[NSString alloc] 
> initWithString:[NSString stringWithFormat:@"%s", buffer]];

You could use -[NSString initWithUTF8String:] instead. Additionally your 
-initWithString:<NSString instance> doesn't make a whole lot of sense in 
general – at best your making a copy, at but more typically your just making 
your code longer (and if a copy were what you were after, -copy is usually 
better form).

>                       MyObject *myObject = [[MyObject alloc] 
> initWithString:line];
>                       
>                       //Do some very interesting things with the line in 
> myObject...
>                       
>                       [myObject doAnInterestingMethod];
>                       NSString * iNeedThisString = [myObject 
> makeAMemoryLeakAndDriveMeCrazy];
> 
>                       
>                       [myObject release];
>                       [line release];
> 
> }


Overall, wrapping this code in an autorelease pool is probably the best way to 
ensure that autoreleased objects don't pile up on you. You can retain the 
iNeedThisString to ensure it survives the pool if necessary.
--
David Duncan

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to