From 9d6154041c9965a9d244fcf27eb49691bb00af3c Mon Sep 17 00:00:00 2001 From: theraven Date: Mon, 4 Jul 2011 12:22:23 +0000 Subject: [PATCH] Make sure that autoreleased returned objects are destroyed when the autorelease pool is destroyed. They were previously being destroyed on thread termination, this ensures that their lifespan is predictable. --- arc.m | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arc.m b/arc.m index 478d79e..e47020c 100644 --- a/arc.m +++ b/arc.m @@ -91,6 +91,13 @@ void objc_autoreleasePoolPop(void *pool) // TODO: Keep a small pool of autorelease pools per thread and allocate // from there. DeleteAutoreleasePool(pool, SELECTOR(release)); +#ifndef NO_PTHREADS + // Ensure that autoreleased return values are destroyed at the correct + // moment. + id tmp = pthread_getspecific(ReturnRetained); + objc_release(tmp); + pthread_setspecific(ReturnRetained, NULL); +#endif } id objc_autorelease(id obj)