I have a question about variable release in global class.

Posted by Beomseok on Stack Overflow See other posts from Stack Overflow or by Beomseok
Published on 2010-03-31T20:48:55Z Indexed on 2010/03/31 20:53 UTC
Read the original article Hit count: 199

Filed under:
|
|
+ (void)findAndCopyOfDatabaseIfNeeded{
NSArray         *path               = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString        *documentsDirectory = [path objectAtIndex:0];

NSFileManager   *fileManager        = [NSFileManager defaultManager];
NSString        *databasePath       = [documentsDirectory stringByAppendingPathComponent:@"DB"];
BOOL success = [fileManager fileExistsAtPath:databasePath];
if(!success){
    NSString *resourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"DB"];
    [fileManager copyItemAtPath:resourcePath toPath:databasePath error:NULL];
}

NSString        *tracePath          = [documentsDirectory stringByAppendingPathComponent:@"Trace"];
BOOL traceDir = [fileManager fileExistsAtPath:tracePath];
if(!traceDir){
    NSString        *resourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Trace"];
    [fileManager copyItemAtPath:resourcePath toPath:tracePath error:NULL];
}


NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy"];

NSDate   *today         = [[NSDate alloc]init];
NSString *resultYear    = [dateFormatter stringFromDate:today];
NSString *traceYearPath = [tracePath stringByAppendingPathComponent:resultYear];
BOOL yearDir = [fileManager fileExistsAtPath:tracePath];
if (!yearDir) {
    [fileManager createDirectoryAtPath:traceYearPath attributes:nil];
}
//[resultYear     release];  ?
//[today      release];  ?
//[dateFormatter  release];  ?

}

I'm using global class like this [ + (void)findAndCopyOfDatabaseIfNeeded ]. hm,, I don't know NSArray, NSString and NSFileManager are released.

Variable release or Not release ? please advice for me.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about release