OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 // Originally these classes are from Chromium. |
| 12 // http://src.chromium.org/viewvc/chrome/trunk/src/base/memory/ref_counted.h?vie
w=markup |
| 13 |
| 14 // |
| 15 // A smart pointer class for reference counted objects. Use this class instead |
| 16 // of calling AddRef and Release manually on a reference counted object to |
| 17 // avoid common memory leaks caused by forgetting to Release an object |
| 18 // reference. Sample usage: |
| 19 // |
| 20 // class MyFoo : public RefCounted<MyFoo> { |
| 21 // ... |
| 22 // }; |
| 23 // |
| 24 // void some_function() { |
| 25 // scoped_refptr<MyFoo> foo = new MyFoo(); |
| 26 // foo->Method(param); |
| 27 // // |foo| is released when this function returns |
| 28 // } |
| 29 // |
| 30 // void some_other_function() { |
| 31 // scoped_refptr<MyFoo> foo = new MyFoo(); |
| 32 // ... |
| 33 // foo = nullptr; // explicitly releases |foo| |
| 34 // ... |
| 35 // if (foo) |
| 36 // foo->Method(param); |
| 37 // } |
| 38 // |
| 39 // The above examples show how scoped_refptr<T> acts like a pointer to T. |
| 40 // Given two scoped_refptr<T> classes, it is also possible to exchange |
| 41 // references between the two objects, like so: |
| 42 // |
| 43 // { |
| 44 // scoped_refptr<MyFoo> a = new MyFoo(); |
| 45 // scoped_refptr<MyFoo> b; |
| 46 // |
| 47 // b.swap(a); |
| 48 // // now, |b| references the MyFoo object, and |a| references null. |
| 49 // } |
| 50 // |
| 51 // To make both |a| and |b| in the above example reference the same MyFoo |
| 52 // object, simply use the assignment operator: |
| 53 // |
| 54 // { |
| 55 // scoped_refptr<MyFoo> a = new MyFoo(); |
| 56 // scoped_refptr<MyFoo> b; |
| 57 // |
| 58 // b = a; |
| 59 // // now, |a| and |b| each own a reference to the same MyFoo object. |
| 60 // } |
| 61 // |
| 62 |
| 63 #ifndef WEBRTC_BASE_SCOPED_REF_PTR_H_ |
| 64 #define WEBRTC_BASE_SCOPED_REF_PTR_H_ |
| 65 |
| 66 |
| 67 // This header is deprecated and is just left here temporarily during |
| 68 // refactoring. See https://bugs.webrtc.org/7634 for more details. |
| 69 #include "webrtc/rtc_base/scoped_ref_ptr.h" |
| 70 |
| 71 #endif // WEBRTC_BASE_SCOPED_REF_PTR_H_ |
OLD | NEW |