Safe way of using ARC semantics for an object pool?

Questions and Answers about all things *OS (macOS, iOS, tvOS, watchOS)

Safe way of using ARC semantics for an object pool?

Postby flickz » Fri Jan 11, 2019 10:59 pm

I've profiled my app and observed that an object pool would be beneficial. However, I want to make sure that I do it in a safe way that does not require consumers to explicitly call a -recycle method when they're done. The only way to do this is using retain count semantics. Here are the options I see:

- Override -dealloc and have it recycle itself (and not call [super dealloc]), as Mike Ash does*. However, the documentation says super should always be called inside -dealloc, and Mike Ash's solution does not do this.
- Override -release and recycle instead of deallocating when the object's retain count hits 0. The documentation for these two methods says that you can do this, so I like this option. However, how would I actually do this? I have an example implementation at ... 26bfda86a8 . The only issue I have with this implementation is that Apple states that NSDeallocateObject should only be used for objects that were allocated with NSAllocateObject. I can arrange to use that function explicitly, but it takes an extraBytes parameter ( ... cateobject), and I'm not sure if it should always be 0.

Any ideas?

* ... ive-c.html
Posts: 7
Joined: Tue Jan 10, 2017 7:32 pm

Return to Questions and Answers

Who is online

Users browsing this forum: No registered users and 5 guests