Automattic\WooCommerce\Internal\ProductFeed\Utils

MemoryManager::collect_garbageprivateWC 1.0

Collect garbage.

Метод класса: MemoryManager{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->collect_garbage(): void;

Код MemoryManager::collect_garbage() WC 10.5.2

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;
		}
	}
}