resource-leak

Is JDK ClassLoader.getResourceAsStream broken? (unclosed resources)

走远了吗. 提交于 2019-12-04 10:00:20
I will try to prove that ClassLoader.getResourceAsStream() is opening two InputStreams , closing none of it and returning only one to client. Is my logic correct? JDK sources are picked from jdk1.8.0_25 I've get into unclosed resources problem using Spring ClassPathResource in interval ( original question ), that is using ClassLoader.getResourceAsStream to get InputStream to a properties file. After investigation, I found that classLoader.getResourceAsStream is getting an URL by URL url = getResource(name); and then it is opening that stream, but URL url = getResource(name) already opens that

Do I need a WOW64 dump for GDI Handle analysis?

三世轮回 提交于 2019-12-04 05:04:05
I'm debugging a potential GDI Handle Leak. Thanks to @Alois Kraus , there is a WinDbg script which performs a handle count. From my debugging sessions, especially for .NET , I find that usually, it's better to have 32-bit dumps of 32-bit processes and 64-bit dumps of 64-bit processes. Unfortunately, with 2 crash dumps I received, the script does not work. Looking deeper into it, I found out that the GdiSharedHandleTable is null in those dumps: 0:000> dt ntdll!_PEB GdiSharedHandleTable @$peb +0x094 GdiSharedHandleTable : (null) Now, on his website , Alois mentions Important: If you are running

Why does this code generate a “Potential resource leak” warning?

无人久伴 提交于 2019-12-04 04:35:25
Eclipse (Juno) gives the following warning: Potential resource leak: 'os' may not be closed at the first line of the try body in this code: 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) { } } } } The method openFileOutput is declared to throw a FileNotFoundException . Is this a false positive? It seems like a fairly vanilla

Hunting down EOutOfResources

北城以北 提交于 2019-12-03 17:58:20
问题 Question: Is there an easy way to get a list of types of resources that leak in a running application? IOW by connecting to an application ? I know memproof can do it, but it slows down so much that the application won't even last a minute. Most taskmanager likes can show the number, but not the type. It is not a problem that the check itself is catastrophic (halts the app process), since I can check with a taskmgr if I'm getting close (or at least I hope) Any other insights on resource leak

Why call Dispose() before main() exits?

久未见 提交于 2019-11-30 08:27:07
问题 My .net service cleans up all its unmanaged resources by calling resourceName.Dispose() in a finally block before the Main() loop exits. Do I really have to do this? Am I correct in thinking that I can’t leak any resources because the process is ending? Windows will close any handles that are no longer being used, right? 回答1: There is no limit to the types of resources that may be encapsulated by an object implementing IDisposable . The vast majority of resources encapsulated by IDisposable

What can cause section handle leaks?

流过昼夜 提交于 2019-11-29 10:05:05
This is a follow-up question to my previous question. As suggested in this answer to my previous question , I used ProcessExplorer to analyze a list of handles that my application is using to find a handle leak. The handles that are leaking are of type Section . What exactly is a section handle, where is it used and what can cause section handles to leak? I'm not using memory mapped files in my code. Quoting Mark Russinovich's Inside Windows 2000 (what is now called Windows Internals), The section object , which the Win32 subsystem calls a file mapping object , represents a block of memory

Hunting down EOutOfResources

只谈情不闲聊 提交于 2019-11-29 06:32:29
Question: Is there an easy way to get a list of types of resources that leak in a running application? IOW by connecting to an application ? I know memproof can do it, but it slows down so much that the application won't even last a minute. Most taskmanager likes can show the number, but not the type. It is not a problem that the check itself is catastrophic (halts the app process), since I can check with a taskmgr if I'm getting close (or at least I hope) Any other insights on resource leak hunting (so not memory) is also welcomed. Background: I've an Delphi 7/2006/2009 app (compiles with all

Why call Dispose() before main() exits?

眉间皱痕 提交于 2019-11-29 06:14:38
My .net service cleans up all its unmanaged resources by calling resourceName.Dispose() in a finally block before the Main() loop exits. Do I really have to do this? Am I correct in thinking that I can’t leak any resources because the process is ending? Windows will close any handles that are no longer being used, right? There is no limit to the types of resources that may be encapsulated by an object implementing IDisposable . The vast majority of resources encapsulated by IDisposable objects will be cleaned up by the operating system when a process shuts down, but some programs may use

Will stream classes or connections considered as a resource leak in Java

会有一股神秘感。 提交于 2019-11-27 23:19:33
Java has no lifetime for an object, this is managed by the garbage collector . And if I use some IO classes without closing it, or some DBConnection , will this considered a resource leak? In another words, will IO object be collected and destroyed by garbage collector, AFAIK, the garbage collector is for memory only. For example: BufferedReader br = new BufferedReader( new FileReader( new File("path") ) ); Yes you are right. Garbage collection frees Java heap (memory) but close() frees OS resources used for open file (number of open files is limited on most system) and assures that the data

Scanner is never closed

孤人 提交于 2019-11-27 13:09:11
I'm working on a game and I came across a little problem with my scanner. I'm getting a resource leak scanner never closed. But I thought my scanner was working before without closing it. But now it ain't. Anyone can help me out here? import java.util.Scanner; public class Main { public static final boolean CHEAT = true; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amountOfPlayers; do { System.out.print("Select the amount of players (1/2): "); while (!scanner.hasNextInt()) { System.out.println("That's not a number!"); scanner.next(); // this is