OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_DEBUG_LEAK_TRACKER_H_ | 5 #ifndef BASE_DEBUG_LEAK_TRACKER_H_ |
6 #define BASE_DEBUG_LEAK_TRACKER_H_ | 6 #define BASE_DEBUG_LEAK_TRACKER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 // Only enable leak tracking in debug builds. | 9 // Only enable leak tracking in debug builds. |
10 #ifndef NDEBUG | 10 #ifndef NDEBUG |
11 #define ENABLE_LEAK_TRACKER | 11 #define ENABLE_LEAK_TRACKER |
12 #endif | 12 #endif |
13 | 13 |
14 #ifdef ENABLE_LEAK_TRACKER | 14 #ifdef ENABLE_LEAK_TRACKER |
15 #include "base/debug/stack_trace.h" | 15 #include "base/debug/stack_trace.h" |
16 #include "base/linked_list.h" | 16 #include "base/linked_list.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #endif // ENABLE_LEAK_TRACKER | 18 #endif // ENABLE_LEAK_TRACKER |
19 | 19 |
20 // LeakTracker is a helper to verify that all instances of a class | 20 // LeakTracker is a helper to verify that all instances of a class |
21 // have been destroyed. | 21 // have been destroyed. |
22 // | 22 // |
23 // It is particularly useful for classes that are bound to a single thread -- | 23 // It is particularly useful for classes that are bound to a single thread -- |
24 // before destroying that thread, one can check that there are no remaining | 24 // before destroying that thread, one can check that there are no remaining |
25 // instances of that class. | 25 // instances of that class. |
26 // | 26 // |
27 // For example, to enable leak tracking for class URLRequest, start by | 27 // For example, to enable leak tracking for class net::URLRequest, start by |
28 // adding a member variable of type LeakTracker<URLRequest>. | 28 // adding a member variable of type LeakTracker<net::URLRequest>. |
29 // | 29 // |
30 // class URLRequest { | 30 // class URLRequest { |
31 // ... | 31 // ... |
32 // private: | 32 // private: |
33 // base::LeakTracker<URLRequest> leak_tracker_; | 33 // base::LeakTracker<URLRequest> leak_tracker_; |
34 // }; | 34 // }; |
35 // | 35 // |
36 // | 36 // |
37 // Next, when we believe all instances of URLRequest have been deleted: | 37 // Next, when we believe all instances of net::URLRequest have been deleted: |
38 // | 38 // |
39 // LeakTracker<URLRequest>::CheckForLeaks(); | 39 // LeakTracker<net::URLRequest>::CheckForLeaks(); |
40 // | 40 // |
41 // Should the check fail (because there are live instances of URLRequest), | 41 // Should the check fail (because there are live instances of net::URLRequest), |
42 // then the allocation callstack for each leaked instances is dumped to | 42 // then the allocation callstack for each leaked instances is dumped to |
43 // the error log. | 43 // the error log. |
44 // | 44 // |
45 // If ENABLE_LEAK_TRACKER is not defined, then the check has no effect. | 45 // If ENABLE_LEAK_TRACKER is not defined, then the check has no effect. |
46 | 46 |
47 namespace base { | 47 namespace base { |
48 namespace debug { | 48 namespace debug { |
49 | 49 |
50 #ifndef ENABLE_LEAK_TRACKER | 50 #ifndef ENABLE_LEAK_TRACKER |
51 | 51 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 StackTrace allocation_stack_; | 128 StackTrace allocation_stack_; |
129 }; | 129 }; |
130 | 130 |
131 #endif // ENABLE_LEAK_TRACKER | 131 #endif // ENABLE_LEAK_TRACKER |
132 | 132 |
133 } // namespace debug | 133 } // namespace debug |
134 } // namespace base | 134 } // namespace base |
135 | 135 |
136 #endif // BASE_DEBUG_LEAK_TRACKER_H_ | 136 #endif // BASE_DEBUG_LEAK_TRACKER_H_ |
OLD | NEW |