问题描述
仔细看看这段代码.....
i意味着当方法调用完成然后本地引用 l_stmt 将被销毁然后JVM将关闭与其相关的所有资源....
plz详细解释我....
thanx
是的你应该自己关闭它。 JVM 可能在收集垃圾之前将其关闭,但这取决于平台。
像Concurrency这样的垃圾收集是Java中的一个事情。是不平台独立。您无法说出何时从内存中删除无用变量的内容。即使您调用System.gc(),也可能不会发生垃圾回收。这取决于您使用的操作系统的内存算法。因此,保持连接打开并希望它在清理时关闭是不安全的,因为你永远不知道实际清理的时间。
look at this code carefullyyyy .....
i mean when the method calling finished then the local reference l_stmt will be destroyed then will JVM close all resources associated with it ....
plz explain me in details ....
thanx
Yes you should close it yourself. The JVM may close it before garbage collecting but that depends on the platform.
Garbage collection like Concurrency is one of those things in Java that are not platform independant. You cannot say when a useless variable''s contents are removed from memory. Even is you call System.gc(), garbage collection may not occur. It depends on the memory algorithms of the OS you are using. So leaving a connection open and hoping it will get closed on cleanup is not safe because you never know when clean up actually takes place.
这篇关于我应该关闭有本地参考的声明?????的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!