Struct GC

Source
pub struct GC<T>
where T: GCTraceable<T> + 'static,
{ /* private fields */ }

Implementations§

Source§

impl<T> GC<T>
where T: GCTraceable<T> + 'static,

Source

pub fn new() -> GC<T>

创建一个新的垃圾回收器,默认回收触发百分比为20%

Source

pub fn new_with_percentage(percentage: usize) -> GC<T>

创建一个新的垃圾回收器,指定回收触发的百分比 例如,new_with_percentage(30)表示当attach次数超过当前对象数的30%时触发回收

Source

pub fn new_with_memory_threshold(memory_threshold: usize) -> GC<T>

创建一个新的垃圾回收器,指定内存阈值(字节) 当分配的内存超过指定阈值时触发回收

Source

pub fn new_with_thresholds(percentage: usize, memory_threshold: usize) -> GC<T>

创建一个新的垃圾回收器,同时指定百分比阈值和内存阈值 任一条件满足时都会触发回收

Source

pub fn attach(&mut self, gc_arc: &GCArc<T>)

Source

pub fn detach(&mut self, gc_arc: &GCArc<T>) -> bool

Source

pub fn collect(&mut self)

Source

pub fn object_count(&self) -> usize

Source

pub fn get_all(&self) -> Vec<GCArc<T>>

Source

pub fn create(&mut self, obj: T) -> GCArc<T>

Source

pub fn allocated_memory(&self) -> usize

获取当前分配的内存估算值(字节)

Source

pub fn set_memory_threshold(&mut self, threshold: Option<usize>)

设置内存阈值,None表示禁用内存阈值触发

Source

pub fn memory_threshold(&self) -> Option<usize>

获取当前内存阈值

Trait Implementations§

Source§

impl<T> Drop for GC<T>
where T: GCTraceable<T> + 'static,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for GC<T>

§

impl<T> RefUnwindSafe for GC<T>

§

impl<T> Send for GC<T>
where T: Sync + Send,

§

impl<T> Sync for GC<T>
where T: Sync + Send,

§

impl<T> Unpin for GC<T>

§

impl<T> UnwindSafe for GC<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.