Skip to content
This repository has been archived by the owner on Dec 1, 2021. It is now read-only.

Possible memory leak #156

Open
paav opened this issue Oct 13, 2017 · 1 comment
Open

Possible memory leak #156

paav opened this issue Oct 13, 2017 · 1 comment

Comments

@paav
Copy link

paav commented Oct 13, 2017

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
Copy link

carere commented Mar 11, 2018

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

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

No branches or pull requests

2 participants