diff --git a/src/Persistence/Array_/Action.php b/src/Persistence/Array_/Action.php index e4f83323d..5c1cc0263 100644 --- a/src/Persistence/Array_/Action.php +++ b/src/Persistence/Array_/Action.php @@ -251,9 +251,16 @@ public function order(array $fields) * * @return $this */ - public function limit(int $limit = null, int $offset = 0) + public function limit(?int $limit, int $offset = 0) { - $this->generator = new \LimitIterator($this->generator, $offset, $limit ?? -1); + // LimitIterator with circular reference is not GCed in PHP 7.4 - ???, see + // https://github.com/php/php-src/issues/7958 + if (\PHP_MAJOR_VERSION < 20) { // TODO update condition once fixed in php-src + $data = array_slice($this->getRows(), $offset, $limit, true); + $this->generator = new \ArrayIterator($data); + } else { + $this->generator = new \LimitIterator($this->generator, $offset, $limit ?? -1); + } return $this; }