I've been reading through a lot of the rookie Java questions on finalize() and find it kind of bewildering that no one has really made it plain that finalize() is an unreliable way to clean up resources. I saw someone comment that they use it to clean up Connections, which is really scary since the only way to come as close to a guarantee that a Connection is closed is to implement try (catc
我已经阅读了很多关于finalize()的新手Java问题,并且发现让人困惑的是没有人真正明白finalize()是清理资源的不可靠方法。 我看到有人评论说他们用它来清理Connections,这真的很可怕,因为唯一能够保证Connection关闭的唯一方法就是最终实现try(catch)。 我没有受过CS的教育,但是我已经在Java中专业编程了近十年,我从未见过任何人在生产系统中实现过finalize()。 这并不意味着它没有它的用途,或者我与之合作过
I want to test if a ThreadLocal has been initialized without actually initializing it. Of course, the code needs to be thread-safe. Ideally I want something like this: class TestableThreadLocal<T> extends ThreadLocal<T> { public boolean isInitialized() { ... } } But how would I implement this method? Edit: Motivation: I have subclassed a ThreadLocal to override i
我想测试一个ThreadLocal是否已经初始化而没有实际初始化它。 当然,代码需要是线程安全的。 理想情况下,我想要这样的东西: class TestableThreadLocal<T> extends ThreadLocal<T> { public boolean isInitialized() { ... } } 但是,我将如何实现这种方法? 编辑:动机:我已经subclassed一个ThreadLocal覆盖initialValue() 。 但是,我并不总是需要初始化,特别是因为它可能导致多类加载
I ran memory Profiler using NetBeans and VisualVM and received the results but do not have a clue how to analyze its results, I studied this article but it does not teach or give a clue on how to interpret the results. I have also found this article about interpreting results on Netbeans 4 but am looking for an article with more details,or a way to interpret the following results to learn. Th
我使用NetBeans和VisualVM运行了内存分析器,并收到了结果,但没有线索如何分析其结果,我研究了这篇文章,但没有教导或提供关于如何解释结果的线索。 我也发现了这篇关于在Netbeans 4上解释结果的文章,但是我正在寻找一篇更详细的文章,或者一种解释以下结果的方法来学习。 您在问题中粘贴的遥测图中确实没有太多的信息。 传达的是什么 您的程序已被监控约3分钟 你的堆利用率略低于200MB(没有特别的) 你有大约90
I am reading about Garbage collection and i am getting confusing search results when i search for String literal garbage collections. I need clarification on following points: If a string is defined as literal at compile time [eg: String str = "java" ] then will it be garbage collected? If use intern method [eg: String str = new String("java").intern() ] then will it be
我正在阅读关于垃圾收集的内容,当我搜索字符串文字垃圾收集时,我正在混淆搜索结果。 我需要澄清以下几点: 如果一个字符串在编译时被定义为文字[例如: String str = "java" ],那么它会被垃圾收集吗? 如果使用实习方法[例如: String str = new String("java").intern() ],那么它将被垃圾收集? 它也将被视为与第1点中的字符串字面值不同。 有些地方提到,只有当String类将被卸载时,文字才会
I need a bit of wisdom from the stackoverflow. I'm going to developp a GUI application which will process xml data via forms. I have selected two options : Java (swing or swt) or Qt. I've already try a basic tutorial with both Qt (Qt designer) and Java (Eclipse). And I must admit that both will fill my needs. The last question I have to solve is how painful will be the deployment
我需要从stackoverflow中获得一点智慧。 我将开发一个GUI应用程序,它将通过表单处理XML数据。 我选择了两个选项:Java(swing或swt)或Qt。 我已经用Qt(Qt designer)和Java(Eclipse)尝试了一个基础教程。 我必须承认,两者都能满足我的需求。 我必须解决的最后一个问题是部署会有多痛苦? 最终用户是非技术人员,因此安装和更新过程必须简单。 Java具有Java Web Start,易于更新; Qt可能会更“打包”而不需要JVM
I get this question asked many times. What is a good way to answer? EDIT : Thanks everyone for all the answers. Can there be memory leak in Java? The answer is that it depends on what kind of memory leak you are talking about. Classic C / C++ memory leaks occur when an application neglects to free or dispose an object when they are done with it, and it leaks. Cyclic references are a sub
我问了很多次这个问题。 什么是一个好的方法来回答? 编辑 :谢谢大家的所有答案。 Java中有没有内存泄漏? 答案是这取决于你在谈论什么样的内存泄漏。 经典的C / C ++内存泄漏发生在应用程序忽略free或dispose对象时发生泄漏。 循环引用是这种情况的一个子情况,应用程序很难知道何时free / dispose ,而忽略这样做。 相关问题是应用程序在释放后使用对象的位置,或试图释放对象两次。 (你可以称后者存在内存泄漏
I was reading a book on programming skills wherein the author asks the interviewee, "How do you crash a JVM?" I thought that you could do so by writing an infinite for-loop that would eventually use up all the memory. Anybody has any idea? The closest thing to a single "answer" is System.exit() which terminates the JVM immediately without proper cleanup. But apart from t
我正在阅读一本关于编程技巧的书,其中作者问受访者,“你如何使JVM崩溃?” 我认为你可以通过编写一个无限的for循环来最终用完所有的内存。 任何人有任何想法? 最接近单个“答案”的是System.exit() ,它会立即终止JVM而不进行正确的清理。 但除此之外,本机代码和资源耗尽是最可能的答案。 或者,您可以在Sun的bug跟踪器上查看您的JVM版本中的错误,其中一些错误允许可重复的崩溃情况。 在32位版本(我们现在通常使用64位
This question already has an answer here: Creating a memory leak with Java 52 answers A simple implementation would have a static list and when doSomething is called, just keep adding the input String to the list. The reason why is because you're storing a strong reference (via the static member) to the strings so the strings cannot be garbage collected.
这个问题在这里已经有了答案: 用Java 52回答创建内存泄漏 一个简单的实现会有一个static列表,当doSomething被调用时,只要继续添加输入String到列表。 之所以会这样,是因为你将一个强引用(通过静态成员)存储到字符串中,因此字符串不能被垃圾收集。
This question already has an answer here: Creating a memory leak with Java 52 answers In short, no. Java has a built-in (and mandatory) garbage collector. C++ does not. Once an Object is no longer reachable (in Java), it is eligible for garbage collection (and the collector may free the memory). A "memory leak" in a memory-managed language like Java doesn't have exactly th
这个问题在这里已经有了答案: 用Java 52回答创建内存泄漏 总之,没有。 Java有一个内置的(和必需的)垃圾收集器。 C ++没有。 一旦Object不再可访问(使用Java),它就有资格进行垃圾回收(并且收集器可以释放内存)。 像Java这样的内存管理语言中的“内存泄漏”与C ++中的“内存泄漏”并不完全相同,因为Java不要求您明确释放已分配的内存。 这样说,你可以通过基本相同的效果。 观察者模式的集合类和实现往往是这方
Possible Duplicate: Creating a memory leak with Java There is a "Garbage Collector" in Java, but does this mean that memory leaks are totally absent in a Java applications? If not, how and why do they happen? I am more interested in scenarios in applications using JavaSE. No - memory leaks can still exists in Java. They are just of a "different kind". Wiki: Memory
可能重复: 用Java创建内存泄漏 Java中有一个“垃圾收集器”,但这是否意味着Java应用程序中完全没有内存泄漏? 如果不是,他们如何以及为何发生? 我对使用JavaSE的应用程序中的场景更感兴趣。 否 - 内存泄漏仍然可以在Java中存在。 他们只是一种“不同类型”。 维基:内存泄漏 计算机科学中的内存泄漏(在这种情况下是泄漏)发生在计算机程序消耗内存但无法将内存释放回操作系统时 。 在Java的情况下(通常),当