Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / base / mac / scoped_nsautorelease_pool.h
blob60af71ae0554336a55a0a4444e10bd3a930ebaa7
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.
5 #ifndef BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_
6 #define BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_
8 #include "base/base_export.h"
9 #include "base/basictypes.h"
11 #if defined(__OBJC__)
12 @class NSAutoreleasePool;
13 #else // __OBJC__
14 class NSAutoreleasePool;
15 #endif // __OBJC__
17 namespace base {
18 namespace mac {
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.
25 class BASE_EXPORT ScopedNSAutoreleasePool {
26 public:
27 ScopedNSAutoreleasePool();
28 ~ScopedNSAutoreleasePool();
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_;
38 private:
39 DISALLOW_COPY_AND_ASSIGN(ScopedNSAutoreleasePool);
42 } // namespace mac
43 } // namespace base
45 #endif // BASE_MAC_SCOPED_NSAUTORELEASE_POOL_H_