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

ICrossSocket := nil 不能自动销毁 #28

Closed
gmxyb opened this issue Jul 17, 2018 · 4 comments
Closed

ICrossSocket := nil 不能自动销毁 #28

gmxyb opened this issue Jul 17, 2018 · 4 comments

Comments

@gmxyb
Copy link

gmxyb commented Jul 17, 2018

_ListenSocket : ICrossSocket;
....
....
_ListenSocket := TCrossSocket.Create(0);
....
....
_ListenSocket := nil; // 不能自动销毁对象,是否存在循环引用??

环境:Windows7 / RAD Studio 10.1

@winddriver
Copy link
Owner

在 _ListenSocket := nil; 前面先调用 _ListenSocket.StopLoop;

@gmxyb
Copy link
Author

gmxyb commented Jul 27, 2018

谢谢。我试过StopLoop,还是会随机出现不能释放。
Create 时自动 StartLoop,但是销毁之前却要手动 StopLoop,这里样的设计是否合理?

@pony5551
Copy link

感觉是接口的坑,最好是可以改为对象池管理对象,我也发现过类似问题。

而且关闭服务器时,会有线程数的accept对象不会被释放,
发现这个是强行退出io都会这样,只有把对像管理起来才能解决这个问题

@winddriver
Copy link
Owner

因为你要是不调用StopLoop,IO线程就不会退出,IO线程有对ICrossSocket对象的引用,所以必须在退出之前调用StopLoop才行,你直接 _ListenSocket := nil 只是减少一次对象的引用计数而已,并不能释放接口对象,接口对象只有在引用计数减到0时才会被释放,这是接口的基本特性。

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

No branches or pull requests

3 participants