Morten Gustafsson
Morten Gustafsson

Reputation: 1889

Methods Memory management in iOS under ARC

What happens Memory wise if I keep calling this method? (Please don’t comment the code, it is just a thought example. )

-(NSMutableArray*)searchForItemsWithString:(NSString *)searchString
{
    NSString *baseUrl = @"http://www.myService.com/";

    NSURL *tempUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",baseUrl, searchString]];

    NSMutableArray *tempResultArray = [[NSMutableArray alloc ] initWithContentsOfURL:tempUrl];

    return tempResultArray;
}

Will tempResultArray keep increasing the reference count, or will ARC do the magic after tempResultArray has been returned, and dealloc it?

Upvotes: 0

Views: 69

Answers (1)

Zev Eisenberg
Zev Eisenberg

Reputation: 8148

ARC will may (see comments) put an autorelease call on tempResultArray before returning it. What happens to it after that is up to the rest of your program. The next time you call this method, a new tempResultArray will be created and the process repeats.

Upvotes: 1

Related Questions