Artifact d6d789a7b7356774b3ad2fb60642477bd3b88f91e6022c600108253caa675eb7:
- File
src/OFAutoreleasePool.h
— part of check-in
[f5927f8a84]
at
2012-07-14 20:00:11
on branch trunk
— New autorelease pools.
This uses the runtime's autorelease pools and implements autorelease
pools in the ObjFW runtime. It therefore uses ObjFW's autorelease pools
when using the ObjFW runtime and Apple's autorelease pools when using
the Apple runtime.These new pools should be ARC-compatible now and finally, it should be
possible to mix OFAutoreleasePools and NSAutoreleasePools again, even
@autoreleasepool is allowed in the mix now. This also means the old
bridge to NSAutoreleasePool should not be required anymore, as both use
the runtime's autorelease pools now.As a bonus, it's significantly faster to use the ObjFW runtime with
ObjFW's autorelease pools than to use Apple's runtime with Apple's
autorelease pools, as a quick benchmark using OFXMLParser on large files
showed. (Note: This is not only due to the different autorelease pools,
but also due to the fact that even with the same autorelease pools it is
faster using the ObjFW runtime, as can be seen in versions prior to this
commit.) (user: js, size: 2201) [annotate] [blame] [check-ins using]
/* * Copyright (c) 2008, 2009, 2010, 2011, 2012 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" /** * \brief A pool that keeps track of objects to release. * * The OFAutoreleasePool class is a class that keeps track of objects that will * be released when the autorelease pool is released. * * Every thread has its own stack of autorelease pools. */ @interface OFAutoreleasePool: OFObject { void *pool; BOOL ignoreRelease; } /** * \brief Adds an object to the autorelease pool at the top of the * thread-specific autorelease pool stack. * * \param object The object to add to the autorelease pool * \return The object */ + (id)addObject: (id)object; + (void)_releaseAll; /** * \brief Releases all objects in the autorelease pool. * * This does not free the memory allocated to store pointers to the objects in * the pool, so reusing the pool does not allocate any memory until the previous * number of objects is exceeded. It behaves this way to optimize loops that * always work with the same or similar number of objects and call relaseObjects * at the end of the loop, which is propably the most common case for * releaseObjects. * * If a garbage collector is added in the future, it will tell the GC that now * is a good time to clean up, as this is often used after a lot of objects * have been added to the pool that should be released before the next iteration * of a loop, which adds objects again. Thus, it is usually a clean up call. */ - (void)releaseObjects; /** * \brief Releases all objects in the autorelease pool and deallocates the pool. */ - (void)release; /** * \brief Releases all objects in the autorelease pool and deallocates the pool. */ - (void)drain; @end