diff options
Diffstat (limited to 'base/memory')
-rw-r--r-- | base/memory/scoped_nsobject.h | 5 | ||||
-rw-r--r-- | base/memory/scoped_nsobject_unittest.mm | 11 |
2 files changed, 16 insertions, 0 deletions
diff --git a/base/memory/scoped_nsobject.h b/base/memory/scoped_nsobject.h index 0656dbe..5d98e3f 100644 --- a/base/memory/scoped_nsobject.h +++ b/base/memory/scoped_nsobject.h @@ -96,6 +96,11 @@ class scoped_nsprotocol { return temp; } + // Shift reference to the autorelease pool to be released later. + NST autorelease() { + return [release() autorelease]; + } + private: NST object_; }; diff --git a/base/memory/scoped_nsobject_unittest.mm b/base/memory/scoped_nsobject_unittest.mm index e61c060..377a3de 100644 --- a/base/memory/scoped_nsobject_unittest.mm +++ b/base/memory/scoped_nsobject_unittest.mm @@ -5,6 +5,7 @@ #include <vector> #include "base/basictypes.h" +#include "base/mac/scoped_nsautorelease_pool.h" #include "base/memory/scoped_nsobject.h" #include "testing/gtest/include/gtest/gtest.h" @@ -40,6 +41,16 @@ TEST(ScopedNSObjectTest, ScopedNSObject) { ASSERT_TRUE(p1 != p5.get()); ASSERT_FALSE(p1 == p5); ASSERT_FALSE(p1 == p5.get()); + + scoped_nsobject<NSObject> p6 = p1; + ASSERT_EQ(3u, [p6 retainCount]); + { + base::mac::ScopedNSAutoreleasePool pool; + p6.autorelease(); + ASSERT_EQ(nil, p6.get()); + ASSERT_EQ(3u, [p1 retainCount]); + } + ASSERT_EQ(2u, [p1 retainCount]); } TEST(ScopedNSObjectTest, ScopedNSObjectInContainer) { |