Question

Suppose in my Database Manager which is singleton.

+ (SWDatabaseManager *)retrieveManager
{
    @synchronized(self)
    {
       if (!sharedSingleton)
       {
           sharedSingleton = [[SWDatabaseManager alloc] init];
       }
       return sharedSingleton;
    }
}

- (NSArray *)getProductDetails:(NSString *)someString 
{
    NSArray *temp = [self getRowsForQuery:someString];
    return temp;
}

- (NSArray *)getRowsForQuery:(NSString *)sql
{
    sqlite3_stmt *statement=nil;
    NSMutableArray *arrayResults = [NSMutableArray arrayWithCapacity:1];
    //
    //Fetching data from database and adds them in to arrayResults
    //
    return arrayResults;
}

Now from some view controller i am calling function of Database manager like this....

[self getProductServiceDidGetDetail:[[SWDatabaseManager retrieveManager] getProductDetail: @"SomeQuery"]

- (void)getProductServiceDidGetDetail:(NSArray *)detailArray 
{
    [self setDataSource:[NSArray arrayWithArray:detailArray]];
    [self.tableView reloadData];
}

Questions are ... When arrayResult of getRowsForQuery will release?

Do i need to assign nil to detailArray of getProductServiceDidGetDetail?

Is there any memory leaks?

Suggestion will be appreciated.

Was it helpful?

Solution

ARC does automatic memory management. So it releases everything (your array), when you are done using it.

ARC works by adding code at compile time to ensure that objects live as long as necessary, but no longer. Conceptually, it follows the same memory management conventions as manual reference counting (described in Advanced Memory Management Programming Guide) by adding the appropriate memory management calls for you.

To help you understand better you might want to read apples docs on ARC.

You will not need to assign nil to the array, nor do you have to worry about memory leaks.

You do not have to (indeed cannot) release instance variables, but you may need to invoke [self setDelegate:nil] on system classes and other code that isn’t compiled using ARC.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top