From 5f0665f8c87ad1abc948a8cb61088cb5ceec83ed Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Wed, 11 Oct 2017 09:50:27 +0200 Subject: [PATCH] Optimize memory consumption of Amp\ByteStream\pipe --- lib/functions.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/functions.php b/lib/functions.php index 1b8b973..d630c07 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -24,7 +24,9 @@ function pipe(InputStream $source, OutputStream $destination): Promise { while (($chunk = yield $source->read()) !== null) { $written += \strlen($chunk); - yield $destination->write($chunk); + $writePromise = $destination->write($chunk); + $chunk = null; // free memory + yield $writePromise; } return $written;