Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I experience a memory leak #38

Closed
kasperkamperman opened this issue Jun 1, 2021 · 2 comments
Closed

I experience a memory leak #38

kasperkamperman opened this issue Jun 1, 2021 · 2 comments

Comments

@kasperkamperman
Copy link

I experiment some kind of memory leak when converting coordinates for multiple times.

Do you see any issues with this code?

PHP 8.0.6
PHPCoord 4.3
Datapack Europe 1.0

require_once __DIR__ . '/vendor/autoload.php';

use PHPCoord\CoordinateReferenceSystem\Projected;
use PHPCoord\CoordinateReferenceSystem\Geographic2D;
use PHPCoord\ProjectedPoint;
use PHPCoord\UnitOfMeasure\Length\Metre;

function convertCoord($easting, $northing)
{
    $crs = Projected::fromSRID(Projected::EPSG_AMERSFOORT_RD_NEW);
    $from = ProjectedPoint::createFromEastingNorthing(
        new Metre($easting),
        new Metre($northing),
        $crs
    );

    $coords = (string) $from->convert(Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84));
    $coords = explode(",", trim($coords, '()'));

    $lonlat[] = floatval($coords[1]);
    $lonlat[] = floatval($coords[0]);

    return $lonlat;
}

function getPointLonLat()
{
    // of course below will be variables, but I experience the issue even calling this function multiple times.
    $x = 94904.701655864;
    $y = 467709.4147013;

    $lonlat = convertCoord($x, $y);

    return $lonlat;
}
@dvdoug
Copy link
Owner

dvdoug commented Jun 1, 2021

Hello @kasperkamperman

How are you detecting the leak? Running the below shows an unchanging number for me (PHP 8.0.5)

for ($i = 0; $i < 1000; $i++) {
   getPointLonLat();
   echo memory_get_usage() . "\n";
}

@kasperkamperman
Copy link
Author

Thanks. I couldn't reproduce the error standalone.

Probably a combination with loading a large file and getting the UnknownConversionException error. Which I could solve by passing the true, to the convert method:
$from->convert(Geographic2D::fromSRID(Geographic2D::EPSG_WGS_84), true)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants