1 // Copyright 2010 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/mac/scoped_nsautorelease_pool.h" 6 7 // Note that this uses the direct runtime interface to the autorelease pool. 8 // https://clang.llvm.org/docs/AutomaticReferenceCounting.html#runtime-support 9 // This is so this can work when compiled for ARC. 10 11 extern "C" { 12 void* objc_autoreleasePoolPush(void); 13 void objc_autoreleasePoolPop(void* pool); 14 } 15 16 namespace base::mac { 17 ScopedNSAutoreleasePool()18ScopedNSAutoreleasePool::ScopedNSAutoreleasePool() 19 : autorelease_pool_(objc_autoreleasePoolPush()) {} 20 ~ScopedNSAutoreleasePool()21ScopedNSAutoreleasePool::~ScopedNSAutoreleasePool() { 22 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 23 objc_autoreleasePoolPop(autorelease_pool_); 24 } 25 26 // Cycle the internal pool, allowing everything there to get cleaned up and 27 // start anew. Recycle()28void ScopedNSAutoreleasePool::Recycle() { 29 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 30 objc_autoreleasePoolPop(autorelease_pool_); 31 autorelease_pool_ = objc_autoreleasePoolPush(); 32 } 33 34 } // namespace base::mac 35