1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_ 6 #define BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_ 7 8 #include "base/base_export.h" 9 #include "base/macros.h" 10 11 #if defined(__OBJC__) 12 @class NSAutoreleasePool; 13 #else // __OBJC__ 14 class NSAutoreleasePool; 15 #endif // __OBJC__ 16 17 namespace base { 18 namespace mac { 19 20 // ScopedNSAutoreleasePool allocates an NSAutoreleasePool when instantiated and 21 // sends it a -drain message when destroyed. This allows an autorelease pool to 22 // be maintained in ordinary C++ code without bringing in any direct Objective-C 23 // dependency. 24 25 class BASE_EXPORT ScopedNSAutoreleasePool { 26 public: 27 ScopedNSAutoreleasePool(); 28 ~ScopedNSAutoreleasePool(); 29 30 // Clear out the pool in case its position on the stack causes it to be 31 // alive for long periods of time (such as the entire length of the app). 32 // Only use then when you're certain the items currently in the pool are 33 // no longer needed. 34 void Recycle(); 35 private: 36 NSAutoreleasePool* autorelease_pool_; 37 38 private: 39 DISALLOW_COPY_AND_ASSIGN(ScopedNSAutoreleasePool); 40 }; 41 42 } // namespace mac 43 } // namespace base 44 45 #endif // BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_ 46