discord-php / DiscordPHP-Http

Asynchronous HTTP client used for communication with the Discord REST API.
MIT License
21 stars 9 forks source link

Anonymous Function Reference Memory Leak #20

Closed ellisonpatterson closed 1 year ago

ellisonpatterson commented 1 year ago

It seems that inside the checkQueue method, the anonymous function defined as the same name is causing a memory leak.

If we forcefully set the variable to null when we will not be calling it recursively, it stops the memory leak from occurring.

SQKo commented 1 year ago

Is this null safety?

ellisonpatterson commented 1 year ago

No it prevents the memory leak as discovered here: https://github.com/discord-php/DiscordPHP-Http/issues/19

It seems that the checkQueue anonymous method never gets cleared from memory after it stops being called, so memory slowly goes up.

After nullifying it, and running the test script from the issue, memory does not increase and stays the same.

SQKo commented 1 year ago

I'm asking if setting them null won't cause problem to those checkQueue() calls since you did not check for that

ellisonpatterson commented 1 year ago

I have not seen any issues with this patch on my bot. It has been running for 24 hours with no problems.

I am setting them null if it's not going to call $checkQueue again.