Resource leak: 'context' is never closed

Posted 博观约取 厚积薄发

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Resource leak: 'context' is never closed相关的知识,希望对你有一定的参考价值。

from: http://stackoverflow.com/questions/14184059/spring-applicationcontext-resource-leak-context-is-never-closed

Since the app context is a ResourceLoader (i.e. I/O operations) it consumes resources that need to be freed at some point. It is also an extension of AbstractApplicationContext which implements Closable. Thus, it‘s got a close() method and can be used in a try-with-resources statement.

try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/userLibrary.xml")) {
  service = context.getBean(UserLibrary.class);
}

Whether you actually need to create this context is a different question (you linked to it), I‘m not gonna comment on that.

It‘s true that the context is closed implicitly when the application is stopped but that‘s not good enough. Eclipse is right, you need to take measures to close it manually for other cases in order to avoid classloader leaks.

以上是关于Resource leak: 'context' is never closed的主要内容,如果未能解决你的问题,请参考以下文章

错误日志:Resource leak: 'xxx' is never closed(Scanner类的注意事项)

Java:Resource leak: 'a' is never closed怎么处理? 代码如下图:

AAPT: error: resource drawable/soil_backgroud_content3 (aka cn.bloghut:drawable/soil_backgroud_conte

数据库内存泄漏——A SQLiteConnection object for database '/data/data/.../databases/....db' was leaked

C++笔记(to be cont'd)

封装WKWebviewController不走dealloc方法