Backed out 2 changesets (bug 1943998) for causing wd failures @ phases.py CLOSED...
[gecko.git] / ipc / chromium / src / base / scoped_nsautorelease_pool.h
blob37d173b028e6f2f4c6865c86c2f1034ddaf55a6f
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 // Copyright (c) 2008 The Chromium Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style license that can be
5 // found in the LICENSE file.
7 #ifndef BASE_SCOPED_NSAUTORELEASE_POOL_H_
8 #define BASE_SCOPED_NSAUTORELEASE_POOL_H_
10 #include "base/basictypes.h"
12 #if defined(XP_DARWIN)
13 # if defined(__OBJC__)
14 @class NSAutoreleasePool;
15 # else // __OBJC__
16 class NSAutoreleasePool;
17 # endif // __OBJC__
18 #endif // XP_DARWIN
20 namespace base {
22 // On the Mac, ScopedNSAutoreleasePool allocates an NSAutoreleasePool when
23 // instantiated and sends it a -drain message when destroyed. This allows an
24 // autorelease pool to be maintained in ordinary C++ code without bringing in
25 // any direct Objective-C dependency.
27 // On other platforms, ScopedNSAutoreleasePool is an empty object with no
28 // effects. This allows it to be used directly in cross-platform code without
29 // ugly #ifdefs.
30 class ScopedNSAutoreleasePool {
31 public:
32 #if !defined(XP_DARWIN)
33 ScopedNSAutoreleasePool() {}
34 void Recycle() {}
35 #else // XP_DARWIN
36 ScopedNSAutoreleasePool();
37 ~ScopedNSAutoreleasePool();
39 // Clear out the pool in case its position on the stack causes it to be
40 // alive for long periods of time (such as the entire length of the app).
41 // Only use then when you're certain the items currently in the pool are
42 // no longer needed.
43 void Recycle();
45 private:
46 NSAutoreleasePool* autorelease_pool_;
47 #endif // XP_DARWIN
49 private:
50 DISALLOW_COPY_AND_ASSIGN(ScopedNSAutoreleasePool);
53 } // namespace base
55 #endif // BASE_SCOPED_NSAUTORELEASE_POOL_H_