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

Fix memory leaks described in issue #179 #202

Open
wants to merge 1 commit into
base: 0.6.x
Choose a base branch
from

Conversation

dmarkic
Copy link

@dmarkic dmarkic commented Sep 26, 2024

Hello,

this is a memory leak fix for 0.6.x branch.

  • Executor calls removeAllListeners() on all commands.
  • Connection will remove all listeners from executor when connection closes
    • Obvious memory-leak here is when LazyConnection opens/closes connection.

Example script:

<?php

// load reactphp-mysql/vendor/autoload.php

$loop = \React\EventLoop\Loop::get();
$factory = new \React\MySQL\Factory();
$connection = $factory->createLazyConnection('localhost');
//$connection = \React\Async\await($factory->createConnection('localhost'));

$pre_memory = 0;

$loop->addPeriodicTimer(
    1,
    function () use ($connection, &$pre_memory) {
        $connection->query('SELECT \'' . str_repeat('A', 1000) . '\'')->then(
            function ($res) use (&$pre_memory) {
                echo " - query done\n";
                $cur_memory = memory_get_usage();
                $new_memory = $cur_memory - $pre_memory;
                echo " - Memory usage: " . memory_get_usage() . " new: " . $new_memory . "\n";
                $pre_memory = $cur_memory;
            },
            function ($e) {
                echo " - query error: " . $e->getMessage() . "\n";
                throw $e;
            }
        );
    }
);

$loop->run();

@dmarkic
Copy link
Author

dmarkic commented Sep 26, 2024

Issue #179

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

Successfully merging this pull request may close these issues.

1 participant