scoped_nsautorelease_pool.mm 807 B

123456789101112131415161718192021222324252627282930
  1. // Copyright (c) 2010 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. #include "base/mac/scoped_nsautorelease_pool.h"
  5. #import <Foundation/Foundation.h>
  6. #include "base/check.h"
  7. namespace base::mac {
  8. ScopedNSAutoreleasePool::ScopedNSAutoreleasePool()
  9. : autorelease_pool_([[NSAutoreleasePool alloc] init]) {
  10. DCHECK(autorelease_pool_);
  11. }
  12. ScopedNSAutoreleasePool::~ScopedNSAutoreleasePool() {
  13. [autorelease_pool_ drain];
  14. }
  15. // Cycle the internal pool, allowing everything there to get cleaned up and
  16. // start anew.
  17. void ScopedNSAutoreleasePool::Recycle() {
  18. [autorelease_pool_ drain];
  19. autorelease_pool_ = [[NSAutoreleasePool alloc] init];
  20. DCHECK(autorelease_pool_);
  21. }
  22. } // namespace base::mac