Search code examples
iosvariablesobjectmemory-managementblock

What's the rule of "__block Variables" memory management?


I read the "Blocks Programming Topics" ducument. But I'm not very clear about the __block Variables's management.

When the __block Variables is a type of standard C scalar(like int, double), everything is Ok. But if it is a object. When I copy the related block variable using Block_copy(). I found the object's retainCount is always 1. So how can I manage the memory? Whether I only need to do is manage the related block variable use Block_release, and the runtime system will take care of the __block Variables.

I'm not a native Engnish speaker, I hope you can understand me.


Solution

  • In non-ARC case __block modifier don't increase retainCount. You have to manually manage the lifetime of the object