objective c - Weird memory leak with Blocks and copying in certain way in ARC -


the following simple code, under arc, in latest xcode (4.6.2) shows leaks when profiled leaks instrument, in ios simulator, in release build configuration -os optimization:

- (bool)application:(uiapplication *)application   didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {     (int = 0; < 10; i++)     {         void (^block)() = ^         {             nslog(@"%d", i);         };          id x = block;         [x copy];     }      return yes; } 

it shows 10 leaked blocks. (it not show leaks optimization turned off; turning off optimization not realistic our app.) strange thing is, looking @ memory management history each of leaked blocks, fine -- each has malloc copy , release; release somehow not deallocate it?

is compiler bug (it using default apple llvm compiler)?

this seems either bug in compiler or leaks instrument, not sure which. should file bug apple.

the same leak happens when shortening code this:

int = 0; void (^block)() = ^{     int y = i; };  id x = block; 

the leak appears if block references local variable parent scope.

do see happening in real production code or in example?


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -