Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions oscars/src/collectors/mark_sweep/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,3 +627,28 @@ mod gc_edge_cases {
collector.collect();
}
}

/// Tests for the standalone WeakGc pointer behavior.
mod weak_gc_tests {
use crate::collectors::mark_sweep::MarkSweepGarbageCollector;
use crate::collectors::mark_sweep::cell::GcRefCell;
use crate::collectors::mark_sweep::pointers::{Gc, WeakGc};
#[test]
fn weak_gc_ephemeron_swept_after_strong_drop() {
let collector = &mut MarkSweepGarbageCollector::default()
.with_arena_size(256)
.with_heap_threshold(512);

let strong = Gc::new_in(GcRefCell::new(42u64), collector);
let _weak = WeakGc::new_in(&strong, collector);

drop(strong);
collector.collect();

assert_eq!(
collector.allocator.borrow().arenas_len(),
0,
"WeakGc ephemeron leaked after strong reference dropped"
);
}
}
Loading