Assuming you have just returned from Tools or Shark with concrete evidence that autocomplete pools are indeed a performance issue in your application ...
Creating your own abstracts pools is the answer to the dilemma. You do this when you create many objects, so as not to create too many at once and either enter the paging hell (on Mac), or receive a warning and / or end memory (iPhone OS).
But auto-detection pools are also objects. They are not free. The consumption of one pool of autoresists is tiny, but in the cycle where you create many objects, you probably create one pool for each object X, merging it and creating another one for the next objects X.
Even then, the pools of abstracts are probably not so many, and therefore they will not be much different. You should see this in your Tools or Shark application: most of the time spent in -[NSAutoreleasePool drain] , in turn, is spent in -[NSObject release] . This time you will spend whether you use the autonomy pool or not.
[ EDIT: As of December 2011, autoplay pools can now be created without an object using the @autoreleasepool . They are probably still not free (at least without ARC), but now they are even cheaper than before.]
Thus, the real solution in such cases is to simply create fewer objects. It could mean:
- Using and reusing buffers, whenever possible, reallocating a previously used buffer when resizing is necessary. You can use the
malloc_good_size function to round the size, to make it less likely that you need to redistribute (you can skip the redistribution if the old required size and the new required size are rounded to the same number). You can also consider only buffer growth, never decreasing it. - Use and reuse of mutable objects. For example, if you create a line and then write it to a document, rather than releasing it and creating a new one, delete its entire contents or replace all old contents with the first part of the βnewβ line.
- Setting the value of X (pool deletion threshold). Higher X values ββmean shorter memory consumption, but fewer pools are created and selected. Lower X means more pools, but less risk of paging or receiving a memory alert. This can hardly make a big difference, unless you raise the X too much or lower it too high.
source share