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: GcGenerationPermanent generation (frozen objects)
enabled: AtomicBoolGC enabled flag
debug: AtomicU32Debug flags
garbage: PyMutex<Vec<PyObjectRef>>gc.garbage list (uncollectable objects with del)
callbacks: PyMutex<Vec<PyObjectRef>>gc.callbacks list
Implementations§
Source§impl GcState
impl GcState
pub fn new() -> Self
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if GC is enabled
Sourcepub fn get_debug(&self) -> GcDebugFlags
pub fn get_debug(&self) -> GcDebugFlags
Get debug flags
Sourcepub fn set_debug(&self, flags: GcDebugFlags)
pub fn set_debug(&self, flags: GcDebugFlags)
Set debug flags
Sourcepub fn get_threshold(&self) -> (u32, u32, u32)
pub fn get_threshold(&self) -> (u32, u32, u32)
Get thresholds for all generations
Sourcepub unsafe fn track_object(&self, obj: NonNull<PyObject>)
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
Sourcepub unsafe fn untrack_object(&self, obj: NonNull<PyObject>)
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).
Sourcepub fn get_objects(&self, generation: Option<i32>) -> Vec<PyObjectRef>
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.
Sourcepub fn maybe_collect(&self) -> bool
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.
Sourcepub fn collect(&self, generation: usize) -> CollectResult
pub fn collect(&self, generation: usize) -> CollectResult
Perform garbage collection on the given generation
Sourcepub fn collect_force(&self, generation: usize) -> CollectResult
pub fn collect_force(&self, generation: usize) -> CollectResult
Force collection even if GC is disabled (for manual gc.collect() calls)
Sourcepub fn get_freeze_count(&self) -> usize
pub fn get_freeze_count(&self) -> usize
Get count of frozen objects
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for GcState
impl !RefUnwindSafe for GcState
impl !Send for GcState
impl !Sync for GcState
impl Unpin for GcState
impl UnsafeUnpin for GcState
impl !UnwindSafe for GcState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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