Professional Documents
Culture Documents
Object Pooling in Objective-C: 3 Answers
Object Pooling in Objective-C: 3 Answers
Object Pooling in Objective-C: 3 Answers
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.
log in
tour
help
Is there a nice way to do this in Objective-C, or do I have to write my own tedious logic?
I'm creating and destroying a little of little state objects per frame in an iPhone game. It would be nice if I could just reuse
objects from a pool.
objective-c
object-pooling
10
3 Answers
Neither Cocoa nor Objective-C does anything particularly helpful for object pools. They don't
do anything to stop you either, but you'll basically have to DIY.
answered May 4 '10 at 22:43
Chuck
156k
16
207
310
What about creating a memory zone? Am I mistaken in thinking that this works as a sort of pool?
Ranking Stackingblocks May 4 '10 at 23:27
1 They can be useful in this situation, but they're very distinct from object pools, at least as I understand
them. Memory zones can conceivably make allocation more efficient and help keep related objects
contiguous, but you still allocate and deallocate as normal inside them. Chuck May 5 '10 at 0:04
The Sparrow framework for the iPhone contains a class called "SPPoolObject". The
framework uses it internally for helper objects that are used extremely often, like points,
rectangles or matrices.
If you inherit from SPPoolObject, the 'dealloc' method does not really delete it; instead, the
memory will be reused for the next alloc'ed object.
It's quite a simple class - you can easily use it for your projects. It does not have any
dependency, so you can easily grab it out of the Sparrow framework ;)
answered Nov 3 '10 at 10:55
PrimaryFeather
441
12
I think that the table View has some sort of pooling mechanism for the different
TableCell
something like that :
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
cellId];
if (cell == nil)
{
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CheckMarkCellIdentifier] autorelease];
}
http://stackoverflow.com/questions/2769380/object-pooling-in-objective-c
1/2
7/28/2015
20
http://stackoverflow.com/questions/2769380/object-pooling-in-objective-c
2/2