use __weak to local variable in ARC

Viewed 222

When you write code like below in ARC

__weak NSMutableArray* array = [[NSMutableArray alloc] init];

The compiler will show you a warning or error and say "Assigning retained object to weak variable. object will be released after assignment".

But if you write like this:

__weak NSMutableArray* array = [NSMutableArray array];

There is no error.

I'm wondering if the second usage is reasonable in some situations? What's the difference between these two codes from memory management perspective? How does it work?

3 Answers
Related