MCPcopy Index your code
hub / github.com/RustPython/RustPython / maybe_collect

Method maybe_collect

crates/vm/src/gc_state.rs:358–372  ·  view source on GitHub ↗

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

(&self)

Source from the content-addressed store, hash-verified

356 /// Called after object allocation.
357 /// Returns true if GC was run, false otherwise.
358 pub fn maybe_collect(&self) -> bool {
359 if !self.is_enabled() {
360 return false;
361 }
362
363 // Check gen0 threshold
364 let count0 = self.generations[0].count.load(Ordering::SeqCst) as u32;
365 let threshold0 = self.generations[0].threshold();
366 if threshold0 > 0 && count0 >= threshold0 {
367 self.collect(0);
368 return true;
369 }
370
371 false
372 }
373
374 /// Perform garbage collection on the given generation
375 pub fn collect(&self, generation: usize) -> CollectResult {

Callers 1

new_refMethod · 0.80

Calls 4

is_enabledMethod · 0.80
thresholdMethod · 0.80
collectMethod · 0.80
loadMethod · 0.45

Tested by

no test coverage detected