diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index dcd4ccd130c80..5a96c69502c98 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -162,6 +162,12 @@ public function getPreview(File $file, $width = -1, $height = -1, $crop = false, throw new NotFoundException('Cached preview size 0, invalid!'); } + // Free memory being used by the embedded image resource. Without this the image is kept in memory indefinitely. + // Garbage Collection does NOT free this memory. We have to do it ourselves. + if ($maxPreviewImage instanceof \OC_Image) { + $maxPreviewImage->destroy(); + } + return $preview; } diff --git a/tests/lib/Preview/GeneratorTest.php b/tests/lib/Preview/GeneratorTest.php index cfb78a05da5e8..256c6d5ff773d 100644 --- a/tests/lib/Preview/GeneratorTest.php +++ b/tests/lib/Preview/GeneratorTest.php @@ -31,7 +31,6 @@ use OCP\Files\SimpleFS\ISimpleFile; use OCP\Files\SimpleFS\ISimpleFolder; use OCP\IConfig; -use OCP\IImage; use OCP\IPreview; use OCP\Preview\IProvider; use OCP\Preview\IProviderV2; @@ -184,7 +183,7 @@ public function testGetNewPreview() { $this->fail('Unexpected provider requested'); })); - $image = $this->createMock(IImage::class); + $image = $this->createMock(\OC_Image::class); $image->method('width')->willReturn(2048); $image->method('height')->willReturn(2048); $image->method('valid')->willReturn(true);