| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2008 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_SCOPED_NSAUTORELEASE_POOL_H_ | |
| 6 #define BASE_SCOPED_NSAUTORELEASE_POOL_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 | |
| 11 #if defined(OS_MACOSX) | |
| 12 #if defined(__OBJC__) | |
| 13 @class NSAutoreleasePool; | |
| 14 #else // __OBJC__ | |
| 15 class NSAutoreleasePool; | |
| 16 #endif // __OBJC__ | |
| 17 #endif // OS_MACOSX | |
| 18 | |
| 19 namespace base { | |
| 20 | |
| 21 // On the Mac, ScopedNSAutoreleasePool allocates an NSAutoreleasePool when | |
| 22 // instantiated and sends it a -drain message when destroyed. This allows an | |
| 23 // autorelease pool to be maintained in ordinary C++ code without bringing in | |
| 24 // any direct Objective-C dependency. | |
| 25 // | |
| 26 // On other platforms, ScopedNSAutoreleasePool is an empty object with no | |
| 27 // effects. This allows it to be used directly in cross-platform code without | |
| 28 // ugly #ifdefs. | |
| 29 class ScopedNSAutoreleasePool { | |
| 30 public: | |
| 31 #if !defined(OS_MACOSX) | |
| 32 ScopedNSAutoreleasePool() {} | |
| 33 void Recycle() { } | |
| 34 #else // OS_MACOSX | |
| 35 ScopedNSAutoreleasePool(); | |
| 36 ~ScopedNSAutoreleasePool(); | |
| 37 | |
| 38 // Clear out the pool in case its position on the stack causes it to be | |
| 39 // alive for long periods of time (such as the entire length of the app). | |
| 40 // Only use then when you're certain the items currently in the pool are | |
| 41 // no longer needed. | |
| 42 void Recycle(); | |
| 43 private: | |
| 44 NSAutoreleasePool* autorelease_pool_; | |
| 45 #endif // OS_MACOSX | |
| 46 | |
| 47 private: | |
| 48 DISALLOW_COPY_AND_ASSIGN(ScopedNSAutoreleasePool); | |
| 49 }; | |
| 50 | |
| 51 } // namespace base | |
| 52 | |
| 53 #endif // BASE_SCOPED_NSAUTORELEASE_POOL_H_ | |
| OLD | NEW |