diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e36836690..f59774558d 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ All notable changes to this project will be documented in this file based on the ### Improvements +* Scroll releases previous ResultSet from memory before calling ES for next data batch [#1740](https://github.com/ruflin/Elastica/pull/1740) + ### Deprecated ## [7.0.0-beta2](https://github.com/ruflin/Elastica/compare/7.0.0-beta1...7.0.0-beta2) diff --git a/lib/Elastica/Scroll.php b/lib/Elastica/Scroll.php index 1a374f6050..7eba6d3114 100644 --- a/lib/Elastica/Scroll.php +++ b/lib/Elastica/Scroll.php @@ -69,6 +69,7 @@ public function current(): ?ResultSet */ public function next() { + $this->_currentResultSet = null; if ($this->currentPage < $this->totalPages) { $this->_saveOptions(); @@ -81,7 +82,6 @@ public function next() } else { // If there are no pages left, we do not need to query ES. $this->clear(); - $this->_currentResultSet = null; } } @@ -121,6 +121,7 @@ public function rewind(): void $this->_search->setOption(Search::OPTION_SCROLL, $this->expiryTime); $this->_search->setOption(Search::OPTION_SCROLL_ID, null); + $this->_currentResultSet = null; $this->_setScrollId($this->_search->search()); $this->_revertOptions();