gh7958.phpt 803 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. GH-7958 (Nested CallbackFilterIterator is leaking memory)
  3. --FILE--
  4. <?php
  5. class Action
  6. {
  7. public \Iterator $iterator;
  8. public function __construct(array $data)
  9. {
  10. $this->iterator = new ArrayIterator($data);
  11. echo '-- c ' . spl_object_id($this) . "\n";
  12. }
  13. public function __destruct()
  14. {
  15. echo '-- d ' . spl_object_id($this) . "\n";
  16. }
  17. public function filter()
  18. {
  19. $this->iterator = new \CallbackFilterIterator($this->iterator, fn() => true);
  20. $this->iterator->rewind();
  21. }
  22. }
  23. $action = new Action(['a', 'b']);
  24. $action->filter();
  25. $action->filter();
  26. print_r(iterator_to_array($action->iterator));
  27. $action = null;
  28. gc_collect_cycles();
  29. echo "==DONE==\n";
  30. ?>
  31. --EXPECT--
  32. -- c 1
  33. Array
  34. (
  35. [0] => a
  36. [1] => b
  37. )
  38. -- d 1
  39. ==DONE==