Tag: 资源泄漏

JAI创建似乎让文件描述符保持打开状态

我有一些旧的代码,直到最近才工作,但现在似乎barf它在使用OpenJDK 6而不是Java SE 6的新服务器上运行。 问题似乎围绕着JAI.create。 我有jpeg文件,我可以扩展并转换为png文件。 此代码过去没有泄漏,但现在已经对运行OpenJDK的盒子进行了移动,文件描述符似乎永远不会关闭,我看到越来越多的tmp文件在服务器上的tmp目录中累积。 这些不是我创建的文件,所以我认为是JAI就是这样做的。 另一个原因可能是新服务器上的堆大小较大。 如果JAI在最终确定时清理,但GC发生频率较低,那么可能由于这个原因而堆积起来。 减少堆大小不是一种选择,我们似乎与增加ulimit有无关的问题。 以下是运行此文件时泄漏的文件示例: /tmp/imageio7201901174018490724.tmp 一些代码: // Processor is an internal class that aggregates operations // performed on the image, like resizing private byte[] processImage(Processor processor, InputStream stream) { byte[] bytes = null; SeekableStream s = null; try { // Read the file from the stream s […]

为什么此代码会生成“潜在资源泄漏”警告?

Eclipse(Juno)发出以下警告: 潜在的资源泄漏:’os’可能不会被关闭 在此代码中try主体的第一行: static void saveDetails(byte[] detailsData) { OutputStream os = null; try { os = sContext.openFileOutput(DETAILS_FILE_NAME, Context.MODE_PRIVATE); os.write(detailsData); } catch (IOException e) { Log.w(LOG_TAG, “Unable to save details”, e); } finally { if (os != null) { try { os.close(); } catch (IOException ignored) { } } } } 声明openFileOutput方法抛出FileNotFoundException 。 这是假阳性吗? 这似乎是一个相当普通的执行路径分析。

eclipse中的资源泄漏警告

在Eclipse我收到了一个警告Resource leak: ‘ps’ is not closed at this location我不明白的Resource leak: ‘ps’ is not closed at this location 。 在我的Java代码中,我将“ps”声明为Prepared Statement,并且我多次使用(并关闭)它。 然后我有以下顺序: try { if(condition) { ps = c.prepareStatement(“UPDATE 1 …”); } else { ps = c.prepareStatement(“UPDATE 2 …”); } ps.executeUpdate(); } catch (SQLException e) { // exception handling } finally { if (null != ps) […]