You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
0: new (CcBox), new-weak (1), new-strong (2), clone-weak (2), drop (1), drop (0), drop (T), clone-weak (3), drop-weak (2), drop-weak (1), drop-weak (0), drop (CcBox)"#
130
+
);
131
+
}
132
+
133
+
#[test]
134
+
fntest_weakref_with_cycles(){
135
+
let log = debug::capture_log(|| {
136
+
debug::NEXT_DEBUG_NAME.with(|n| n.set(1));
137
+
let a:Cc<RefCell<Vec<Box<dynTrace>>>> = Cc::new(RefCell::new(Vec::new()));
138
+
debug::NEXT_DEBUG_NAME.with(|n| n.set(2));
139
+
let b:Cc<RefCell<Vec<Box<dynTrace>>>> = Cc::new(RefCell::new(Vec::new()));
140
+
a.borrow_mut().push(Box::new(b.clone()));
141
+
b.borrow_mut().push(Box::new(a.clone()));
142
+
let wa = a.downgrade();
143
+
let wa1 = wa.clone();
144
+
let wb = b.downgrade();
145
+
drop(a);
146
+
drop(b);
147
+
assert!(wa.upgrade().is_some());
148
+
assert!(wb.upgrade().is_some());
149
+
assert_eq!(collect::collect_thread_cycles(),2);
150
+
assert!(wa.upgrade().is_none());
151
+
assert!(wa1.upgrade().is_none());
152
+
assert!(wb.upgrade().is_none());
153
+
assert!(wb.clone().upgrade().is_none());
154
+
});
155
+
assert_eq!(
156
+
log,
157
+
r#"
158
+
1: new (CcBoxWithGcHeader)
159
+
2: new (CcBoxWithGcHeader), clone (2)
160
+
1: clone (2), new-weak (1), clone-weak (2)
161
+
2: new-weak (1)
162
+
1: drop (1)
163
+
2: drop (1)
164
+
1: new-strong (2), drop (1)
165
+
2: new-strong (2), drop (1)
166
+
collect: collect_thread_cycles
167
+
2: gc_traverse
168
+
1: trace, gc_traverse
169
+
2: trace
170
+
collect: 2 unreachable objects
171
+
2: gc_clone (2)
172
+
1: gc_clone (2)
173
+
2: drop (T)
174
+
1: drop (1), drop (T)
175
+
2: drop (1), drop (0)
176
+
1: drop (0)
177
+
2: clone-weak (2), drop-weak (1), drop-weak (0), drop (CcBoxWithGcHeader)
178
+
1: drop-weak (1), drop-weak (0), drop (CcBoxWithGcHeader)"#
179
+
);
180
+
}
181
+
112
182
#[test]
113
183
fntest_drop_by_ref_count(){
114
184
let log = debug::capture_log(|| test_small_graph(3,&[],0,0));
0 commit comments