Check if automatic GC should run and run it if needed. Called after object allocation. Returns true if GC was run, false otherwise.
(&self)
| 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 { |
no test coverage detected