Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find Objective-C Blocks in Allocations or Leaks Instruments

First time question, so don't hold that against me...

For standard objects as well as sub-classes that I create, it is fairly straightforward to find in the Allocations or the Leaks Instruments a particular object. i.e. if I want to see a subclass of UIViewController called ViewController, I can scroll through the Allocations instrument and see the number of living objects increasing and decreasing. Similarly, if that object is leaked the Leaks Instrument will list it. I can even search for specific objects.

However, I'm not sure what to look for when looking for Objective-C blocks. I've noticed in the Leaks Instrument that a leaked block turns up as __NSMallocBlock. However, when using the Allocations Instrument a search for __NSMallocBlock does not show up.

Any ideas what to look for in the Allocations Instrument to track Objective-C blocks?

Many Thanks

like image 501
timthetoolman Avatar asked Nov 22 '11 19:11

timthetoolman


1 Answers

It seems, at least as of Xcode 4.2.1, that Blocks (as in (^), I'll use uppercase/bold for those) show up in the Allocations Instrument as just general Malloc memory blocks (as in chunks of memory, lowercase not bold for those).

So Malloc NN Bytes where NN is the number of bytes required for that Block. Usually Malloc 32 or Malloc 64, depending on what that Block may have captured.

Of course there are most likely plenty of other Malloc blocks of the same size. If you sort by Responsible Caller, that may help you filter them out.

like image 154
Firoze Lafeer Avatar answered Sep 21 '22 12:09

Firoze Lafeer