Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ impl ObjectSpace {
Cc::new_in_space(value, self)
}

/// Leak all objects allocated in this space
pub fn leak(&self) {
*self.list.borrow_mut() = new_gc_list();
}

// TODO: Consider implementing "merge" or method to collect multiple spaces
// together, to make it easier to support generational collection.
}
Expand Down Expand Up @@ -247,6 +252,11 @@ pub fn count_thread_tracked() -> usize {

thread_local!(pub(crate) static THREAD_OBJECT_SPACE: ObjectSpace = ObjectSpace::default());

/// Acquire reference to thread-local global object space
pub fn with_thread_object_space<R>(handler: impl FnOnce(&ObjectSpace) -> R) -> R {
THREAD_OBJECT_SPACE.with(handler)
}

/// Create an empty linked list with a dummy GcHeader.
pub(crate) fn new_gc_list() -> Pin<Box<GcHeader>> {
let pinned = Box::pin(GcHeader::empty());
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ mod trace;
mod trace_impls;

pub use cc::{Cc, RawCc, RawWeak, Weak};
pub use collect::{collect_thread_cycles, count_thread_tracked, ObjectSpace};
pub use collect::{
collect_thread_cycles, count_thread_tracked, with_thread_object_space, ObjectSpace,
};
pub use trace::{Trace, Tracer};

#[cfg(feature = "sync")]
Expand Down
13 changes: 12 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::debug;
use crate::testutil::test_small_graph;
use crate::{collect, Cc, Trace, Tracer};
use crate::{debug, with_thread_object_space};
use std::cell::Cell;
use std::cell::RefCell;
use std::ops::Deref;
Expand Down Expand Up @@ -509,6 +509,17 @@ fn test_trace_impl_double_visits() {
}
}

#[test]
#[ignore = "causes memory leak, thus causing valgrind to error"]
fn leak() {
let a = Cc::new(1);
let b = Cc::new((a.clone(), 1));
with_thread_object_space(|s| s.leak());
assert_eq!(crate::count_thread_tracked(), 0);
assert_eq!(*a, 1);
let _ = b;
}

#[cfg(not(miri))]
quickcheck::quickcheck! {
fn test_quickcheck_16_vertex_graph(edges: Vec<u8>, atomic_bits: u16, collect_bits: u16) -> bool {
Expand Down