Automattic\WooCommerce\Internal\ProductFeed\Utils
MemoryManager::collect_garbage
Collect garbage.
Method of the class: MemoryManager{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->collect_garbage(): void;
MemoryManager::collect_garbage() MemoryManager::collect garbage code WC 10.8.1
private function collect_garbage(): void {
static $gc_threshold = 5000;
static $gc_too_low_in_a_row = 0;
static $gc_too_high_in_a_row = 0;
$gc_threshold_step = 2_500;
$gc_status = gc_status();
if ( $gc_threshold > $gc_status['threshold'] ) {
// If PHP managed to collect memory in the meantime and established threshold lower than ours, just use theirs.
$gc_threshold = $gc_status['threshold'];
}
if ( $gc_status['roots'] > $gc_threshold ) {
$collected = gc_collect_cycles();
if ( $collected < 100 ) {
if ( $gc_too_low_in_a_row > 0 ) {
$gc_too_low_in_a_row = 0;
// Raise GC threshold if we collected too little twice in a row.
$gc_threshold += $gc_threshold_step;
$gc_threshold = min( $gc_threshold, 1_000_000_000, $gc_status['threshold'] );
} else {
++$gc_too_low_in_a_row;
}
$gc_too_high_in_a_row = 0;
} else {
if ( $gc_too_high_in_a_row > 0 ) {
$gc_too_high_in_a_row = 0;
// Lower GC threshold if we collected more than enough twice in a row.
$gc_threshold -= $gc_threshold_step;
$gc_threshold = max( $gc_threshold, 5_000 );
} else {
++$gc_too_high_in_a_row;
}
$gc_too_low_in_a_row = 0;
}
}
}