获得所有资源的完整释放,如 System.exit(0) 中所示
这就是问题所在。我正在开发一个小型 Java 工具,它由 2 个步骤组成(读取和写入,然后分析先前创建的文件)。
由于这两个步骤在堆空间数量方面相当繁重,因此我想在继续之前释放所有资源并清空内存(如 System.exit(0) 中)。
是否可以?我怎样才能做到这一点?
This is the problem. I'm working on a little Java tool which is composed of 2 steps (read & write then analysis of the previously created file).
As the two steps are quite heavy in terms of quantity of heap space, I would like to release all the resources and empty the memory before going ahead (as in System.exit(0)).
Is it possible? How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您坚持完全释放资源,您可以拥有一个主进程,该进程作为子进程启动读取、写入和分析阶段,并在完成时以
System.exit(0)
终止。If you are insistent on a full release of resources you could have a master process which starts the read and write and analysis phases as subprocess which can terminate with
System.exit(0)
when they are complete.Java 的 GC 应该照顾你的内存。如果一个对象没有被引用,那么应该没问题。如果您有打开的文件或流,请明确关闭它们。否则,你应该很好。您是否正在寻找任何导致问题并需要帮助的具体内容?
Java's GC should take care of your memory. If an object is not referenced, you should be fine. If you have open Files or streams, close them explicitly. Otherwise, you should be good. Is there anything specific that you looking for that is causing an issue and need help with?