Skip to content

Unset callback after stop #12

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

Closed
wants to merge 1 commit into from
Closed

Unset callback after stop #12

wants to merge 1 commit into from

Conversation

Slamdunk
Copy link
Contributor

As of yet, a Process instance can't free memory.
The built-in callback has a self-reference to the intance not cleared after instance destruction.
I've tried to change both buildCallback and https://github.com/symfony/process/blob/v2.7.6/Process.php#L1373 usage to avoid self-referencing, but it can't be done without breaking BC, and the memory issue is still there.

A simple test script (that obiously can't be embedded in unit-tests)

$echo = function($inc){
    echo (memory_get_usage(true) / 1000000) . ' MB ' . $inc . PHP_EOL;
};
for ($inc = 0; $inc < 10000; $inc++) {
    $process = new Symfony\Component\Process\Process('echo 1');
    $process->mustRun();
    $process->stop();
    unset($process);

    $echo($inc);
}

Before:

1.572864 MB 0
5.505024 MB 9999

After:

1.572864 MB 0
1.572864 MB 9999

Ok, in this simple scenario 4 MB of RAM is nothing, but in our business app full of IOC where unset-ting is hard, our RAM explodes.

After stop(), the callback is no longer necessary.

@Slamdunk
Copy link
Contributor Author

Just to be clear, the garbage collector in the previous example was already active.
Deactivating it manually, which somewhere is needed to avoid particluar segfaults, obiously leads to worse scenarios:

Before:

 gc_disable();
 1.572864 MB 0
29.360128 MB 9999

After:

 gc_disable();
 1.572864 MB 0
 1.572864 MB 9999

@Slamdunk
Copy link
Contributor Author

Slamdunk commented Dec 2, 2015

Closed in favor of symfony/symfony#16798

@Slamdunk Slamdunk closed this Dec 2, 2015
@Slamdunk Slamdunk deleted the patch-1 branch December 2, 2015 09:25
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