Skip to content

Memory issue #29

@dansleboby

Description

@dansleboby

Hi,

Here is my test script:

<?php

require 'vendor/autoload.php';

use lsolesen\pel\PelJpeg;

function bytes($size) {
	$unit = ['b', 'kb', 'mb', 'gb', 'tb', 'pb'];
	return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2) . ' ' . $unit[$i];
}

$files = glob("dsc*.{JPG,jpeg}", GLOB_BRACE);

foreach($files as $imagePath) {
	echo "Processing file: " . $imagePath . PHP_EOL;
	try {
		$jpeg = new PelJpeg($imagePath);
	} catch(Exception $e) {
		echo 'Error: ' . $e->getMessage() . PHP_EOL;
	}
	printf("MEM:  %s\nPEAK: %s\n", bytes(memory_get_usage()), bytes(memory_get_peak_usage()));
}
The profile will be stored in your Personal environment. The "--environment" option can be used to specify the target environment.
Processing file: dsc00004_1700085011.JPG
MEM:  18.02 mb
PEAK: 18.05 mb
Processing file: dsc00005_1700085017.JPG
MEM:  34.11 mb
PEAK: 34.12 mb
Processing file: dsc00006_1700085022.JPG
MEM:  50.2 mb
PEAK: 50.21 mb
Processing file: dsc00010_1731530648.JPG
MEM:  66.29 mb
PEAK: 66.3 mb
Processing file: dsc00011_1731530660.JPG
MEM:  82.38 mb
PEAK: 82.39 mb
Processing file: dsc00012_1731530667.JPG
MEM:  98.47 mb
PEAK: 98.48 mb

Blackfire run completed
Graph                 https://blackfire.io/profiles/f3f67423-90f3-4687-85b2-f17b041b4b83/graph
Timeline              https://blackfire.io/profiles/f3f67423-90f3-4687-85b2-f17b041b4b83/graph?settings%5Bdimension%5D=timeline
No tests!             Create some now https://docs.blackfire.io/testing-cookbooks/tests
No recommendations

CPU Time     22.6ms
Memory       97.5MB
Wall Time    54.1ms
I/O Wait     31.5ms
Network         n/a     n/a     n/a
SQL             n/a     n/a

I also try to add

$jpeg = null;
gc_collect_cycles();

But it change nothing

I think the issue is coming from the clone class, but I'm not shure:

$c = clone $this;

Test env ( also test : (8.4.1, 8.2.26) )

PHP 8.2.14 (cli) (built: Dec 20 2023 10:19:26) (NTS Visual C++ 2019 x64)
Copyright (c) The PHP Group
Zend Engine v4.2.14, Copyright (c) Zend Technologies
    with blackfire v1.92.30~win-x64-non_zts82, https://blackfire.io, by Blackfire

Microsoft Windows 11 Pro 10.0.22631 build 22631

Thanks for time and help

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions