-
Notifications
You must be signed in to change notification settings - Fork 234
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
协程的底层有一处写的有问题,会出现内存溢出 #48
Comments
已知的问题, 循环引用会影响垃圾回收, 导致 gcroot 的 scan 过程的耗时增加 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
文件 https://github.com/zanphp/coroutine/blob/master/src/Task.php 第50行如下:
这个
$this->scheduler = new Scheduler($this);
这个会把 Scheduler 放在自己的寄存器里,然而 Scheduler 这个对象又把 Task 放在了自己的 task 变量里。形成了相互引用。在处理完毕后并不会释放对象,只有在php垃圾回收机制下才会被清理。不信的话,可以加会发现并未协程执行完毕后这个方法并未被执行,内存中还存在。
建议Task中加:
Scheduler 中加:
并在
Signal::TASK_KILLED
和Signal::TASK_DONE
时调用。这样在协程处理完毕后,会立即释放对象,避免内存溢出。The text was updated successfully, but these errors were encountered: