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

Replace shutdown handlers with destructors #81

Merged
merged 2 commits into from
Sep 22, 2023

Conversation

jessarcher
Copy link
Member

@jessarcher jessarcher commented Sep 21, 2023

This PR fixes a memory leak by:

  • Replacing calls to register_shutdown_handler with class destructors. (thanks @nunomaduro 🙌)
  • Clearing the event listeners to remove any circular references in callback functions that would prevent GC.

I've also removed redundant calls to restore the cursor and TTY now that the destructor will handle it immediately after each prompt, regardless of whether it's successful or fails due to exception, exit, or SIGINT/Ctrl+C.

Best viewed with "Hide whitespace" enabled.

{
parent::__destruct();

if (! empty($this->pid)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to me, that you want to do if ($this->pid > 0)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The destructor can be called before the fork occurs, so this property would not be initialised yet.

isset($this->pid) && $this->pid > 0 would work, but at that point, it's effectively the same as ! empty($this->pid) given that $this->pid is an int.

src/Spinner.php Outdated Show resolved Hide resolved
@jessarcher jessarcher added the bug label Sep 22, 2023
@jessarcher jessarcher marked this pull request as ready for review September 22, 2023 00:04
@taylorotwell taylorotwell merged commit e060aae into main Sep 22, 2023
5 checks passed
@taylorotwell taylorotwell deleted the remove-shutdown-handlers branch September 22, 2023 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants