graphaware / neo4j-php-ogm

Neo4j Object Graph Mapper for PHP
MIT License
153 stars 55 forks source link

Possible memory leak #156

Open paav opened 6 years ago

paav commented 6 years ago

Hello.

I have a memory leak in my application. If I comment out code related to the neo4j-php-ogm mapper, the leak goes away.

I created a test application as described in this tutorial.

When I run this code with empty database:

<?php

// list-persons.php

require_once 'bootstrap.php';

$personsRepository = $entityManager->getRepository(\Demo\Person::class);

const ITERATIONS_COUNT = 100000;
$i = 0;
echo sprintf("Initial memory usage: %s\n", memory_get_usage());

do {
    $person = $personsRepository->find(1);
    $i++;
} while ($i < ITERATIONS_COUNT);

echo sprintf("Memory usage after %d iterations: %s\n", ITERATIONS_COUNT, memory_get_usage());

I get this output:

> php memory-leak-test.php
// bootstrap.php
Initial memory usage: 2159776
Memory usage after 100000 iterations: 11664752

Can I somehow fix that memory leak?

carere commented 6 years ago

Hello,

I can't really see the memory leak, i assume that PHP's garbage collector will clear data after the echo call, at the end of the processus / function.

So if you don't clear data after each iteration (eg. unset($person) or $person = null) you ain't gonna see anything :) Keep in mind that garbage collector looks for object to unset at the end of each function.

Nevertheless, for testing purpose, i suggest to create a bash file which call your php script, and in order to check the memory usage, you can use some system command to mesure it, before and after your script execution :)

Hope this help