0
votes

I'm using a GTMLogger functions for formatted logging in my application. This application creates real-time posix threads (audio packets processing). Sometimes we need to perform a logging from within these non-Cocoa threads. GTMLogger creates autoreleased objects and I thought to put an @autoreleasepool block on GTMLogger calls in the function, that logs from non-Cocoa threads, but I'm afraid it will affect the performance.

My question is - can I somehow create the autorelease pool and associate it with the current posix thread, so the pool is created only once per thread and not each time the log function is called?

Thanks in advance

2
When you create the pthread you pass it a method to call, so can't you put @autoreleasepool in this top-level method, just like main.m in an Xcode-generate app?trojanfoe
that's the problem, the thread is not created in my code, rather in some 3rd party SDK library. The code that is actually calls this function doesn't actually know which thread it's called from.Nava Carmon

2 Answers

1
votes

Under ARC, using @autoreleasepool is quite fast. If you're concerned about performance in there, I would worry much more about avoiding unnecessary logging calls in the first place than about the autorelease pool.

You can't generally create a pool that is associated with "the thread" if the thread is long-lived. You need to to drain the pool periodically, and that won't happen if you just bracket the entire thread main function in an @autoreleasepool{} or anything similar to that.

0
votes

Well, if you don't have control over the thread's main function, then I guess the best you can do is place autorelease pools where that library "calls out" into code that you control.