[英]Are there any alternative concepts for handling unmanaged resources in garbage collected languages?
Garbage collected object oriented programming languages reclaim unused memory automatically, but all other kinds of resources (ie files, sockets...) still require manual release since finalizers cannot be trusted to run in time (or at all). 垃圾收集的面向对象编程语言会自动回收未使用的内存,但是所有其他类型的资源(即文件,套接字等)仍然需要手动释放,因为终结器无法及时(或完全)运行。
Therefore such resource objects usually provide some kind of "close" - or "dispose" -method/pattern, which can be problematic for a number of reasons: 因此,此类资源对象通常提供某种“关闭”或“处置”的方法/模式,由于多种原因,这可能是有问题的:
So, are there any alternative concepts/approaches for properly releasing such resources? 因此,是否有其他替代概念/方法可以正确释放这些资源? Any papers/research in that direction?
在这个方向上有任何论文/研究吗?
One approach (in languages that support it) is to manually trigger a garbage collection event to cause finalizers to run. 一种方法(使用支持它的语言)是手动触发垃圾回收事件以使终结器运行。 However, some languages (like Java) do not provide a reliable mechanism for doing so.
但是,某些语言(如Java)没有提供可靠的机制。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.