Skip to content

Commit

Permalink
fix leak by not using LimitIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jan 17, 2022
1 parent c85d753 commit 0572474
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Persistence/Array_/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0572474

Please sign in to comment.