gc_collect_cycles

Supported Versions: PHP 5 >= 5.3.0, PHP 7, PHP 8
Forces collection of any existing garbage cycles
<?php gc_collect_cycles(): int
<?php             $this->markTestSkipped('Not supported on legacy Promise v1 API');

        }



        gc_collect_cycles();

        gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on



        $dns = new Deferred();
<?php         }



        gc_collect_cycles();

        gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on



        $dns = new Deferred();

        $this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('example.com'))->willReturn($dns->promise());
<?php         $dns->reject(new \RuntimeException('DNS failed'));

        unset($promise, $dns);



        $this->assertEquals(0, gc_collect_cycles());

    }



    public function testRejectionAfterDnsLookupShouldNotCreateAnyGarbageReferences()
<?php             $this->markTestSkipped('Not supported on legacy Promise v1 API');

        }



        gc_collect_cycles();



        $dns = new Deferred();

        $this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('example.com'))->willReturn($dns->promise());
<?php         $tcp->reject(new \RuntimeException('Connection failed'));

        unset($promise, $dns, $tcp);



        $this->assertEquals(0, gc_collect_cycles());

    }



    public function testRejectionAfterDnsLookupShouldNotCreateAnyGarbageReferencesAgain()
<?php             $this->markTestSkipped('Not supported on legacy Promise v1 API');

        }



        gc_collect_cycles();



        $dns = new Deferred();

        $this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('example.com'))->willReturn($dns->promise());
<?php         unset($promise, $dns, $tcp);



        $this->assertEquals(0, gc_collect_cycles());

    }



    public function testCancelDuringDnsLookupShouldNotCreateAnyGarbageReferences()
<?php             $this->markTestSkipped('Not supported on legacy Promise v1 API');

        }



        gc_collect_cycles();



        $dns = new Deferred(function () {

            throw new \RuntimeException();
<?php         $promise->cancel();

        unset($promise, $dns);



        $this->assertEquals(0, gc_collect_cycles());

    }



    public function testCancelDuringTcpConnectionShouldNotCreateAnyGarbageReferences()
<?php             $this->markTestSkipped('Not supported on legacy Promise v1 API');

        }



        gc_collect_cycles();



        $dns = new Deferred();

        $this->resolver->expects($this->once())->method('resolve')->with($this->equalTo('example.com'))->willReturn($dns->promise());
<?php         $promise->cancel();

        unset($promise, $dns, $tcp);



        $this->assertEquals(0, gc_collect_cycles());

    }



    private function throwRejection($promise)
<?php         $connector = new Connector(array('timeout' => false));



        gc_collect_cycles();

        gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on



        $promise = $connector->connect('8.8.8.8:80');
<?php         $connector = new Connector(array('timeout' => false));



        gc_collect_cycles();

        gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on



        $promise = $connector->connect('8.8.8.8:80');

        $promise->cancel();
<?php         $promise->cancel();

        unset($promise);



        $this->assertEquals(0, gc_collect_cycles());

    }



    public function testCancellingPendingConnectionShouldNotCreateAnyGarbageReferences()
<?php         $connector = new Connector(array());



        gc_collect_cycles();

        $promise = $connector->connect('8.8.8.8:80');

        $promise->cancel();

        unset($promise);