Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top