Skip to main content

GcState

Struct GcState 

Source
pub struct GcState {
    pub generations: [GcGeneration; 3],
    pub permanent: GcGeneration,
    pub enabled: AtomicBool,
    pub debug: AtomicU32,
    pub garbage: PyMutex<Vec<PyObjectRef>>,
    pub callbacks: PyMutex<Vec<PyObjectRef>>,
    /* private fields */
}
Expand description

Global GC state

Fields§

§generations: [GcGeneration; 3]

3 generations (0 = youngest, 2 = oldest)

§permanent: GcGeneration

Permanent generation (frozen objects)

§enabled: AtomicBool

GC enabled flag

§debug: AtomicU32

Debug flags

§garbage: PyMutex<Vec<PyObjectRef>>

gc.garbage list (uncollectable objects with del)

§callbacks: PyMutex<Vec<PyObjectRef>>

gc.callbacks list

Implementations§

Source§

impl GcState

Source

pub fn new() -> Self

Source

pub fn is_enabled(&self) -> bool

Check if GC is enabled

Source

pub fn enable(&self)

Enable GC

Source

pub fn disable(&self)

Disable GC

Source

pub fn get_debug(&self) -> GcDebugFlags

Get debug flags

Source

pub fn set_debug(&self, flags: GcDebugFlags)

Set debug flags

Source

pub fn get_threshold(&self) -> (u32, u32, u32)

Get thresholds for all generations

Source

pub fn set_threshold(&self, t0: u32, t1: Option<u32>, t2: Option<u32>)

Set thresholds

Source

pub fn get_count(&self) -> (usize, usize, usize)

Get counts for all generations

Source

pub fn get_stats(&self) -> [GcStats; 3]

Get statistics for all generations

Source

pub unsafe fn track_object(&self, obj: NonNull<PyObject>)

Track a new object (add to gen0). O(1) — intrusive linked list push_front, no hashing.

§Safety

obj must be a valid pointer to a PyObject

Source

pub unsafe fn untrack_object(&self, obj: NonNull<PyObject>)

Untrack an object (remove from GC lists). O(1) — intrusive linked list remove by node pointer.

§Safety

obj must be a valid pointer to a PyObject that is currently tracked. The object’s memory must still be valid (pointers are read).

Source

pub fn get_objects(&self, generation: Option<i32>) -> Vec<PyObjectRef>

Get tracked objects (for gc.get_objects) If generation is None, returns all tracked objects. If generation is Some(n), returns objects in generation n only.

Source

pub fn maybe_collect(&self) -> bool

Check if automatic GC should run and run it if needed. Called after object allocation. Returns true if GC was run, false otherwise.

Source

pub fn collect(&self, generation: usize) -> CollectResult

Perform garbage collection on the given generation

Source

pub fn collect_force(&self, generation: usize) -> CollectResult

Force collection even if GC is disabled (for manual gc.collect() calls)

Source

pub fn get_freeze_count(&self) -> usize

Get count of frozen objects

Source

pub fn freeze(&self)

Freeze all tracked objects (move to permanent generation). Lock order: generation_lists[i] → permanent_list (consistent with unfreeze).

Source

pub fn unfreeze(&self)

Unfreeze all objects (move from permanent to gen2). Lock order: generation_lists[2] → permanent_list (consistent with freeze).

Trait Implementations§

Source§

impl Default for GcState

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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, U> ExactFrom<T> for U
where U: TryFrom<T>,

Source§

fn exact_from(value: T) -> U

Source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

Source§

fn exact_into(self) -> U

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

Source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

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.
Source§

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

Source§

fn wrapping_into(self) -> U

Source§

impl<T> PyThreadingConstraint for T