I'm about to start writing an iOS game and I'm going to use mainly C++/C for the core gameplay logic.

I really like pre-allocating everything in the game and try to avoid any dynamic allocations as much as possible. With my own C++/C code it's not a big deal. However there are some ObjC libraries which I'd like to re-use and I'm not sure how to inject my custom memory allocator to Cocoa based classes.

Is there any central 'inject point' in Cocoa where I can do that?

  • \$\begingroup\$ Why are you trying to inject your custom memory allocator into other libraries? This sounds like obsessive pre-optimization. \$\endgroup\$
    – thedaian
    Aug 26, 2011 at 13:39
  • \$\begingroup\$ I'd like to know exactly how much memory is utilized and in what components. \$\endgroup\$
    – pachanga
    Aug 26, 2011 at 13:46
  • 4
    \$\begingroup\$ @thedaian: On the contrary, injecting memory allocators is a key part of measurement, which is exactly how you optimize properly. \$\endgroup\$
    – user744
    Aug 26, 2011 at 14:33

1 Answer 1


This is all highly theoretical but you may be able to use categories (Mac Developer Tips) to override NSObjects (Apple Developer) alloc and dealloc methods.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .