background preloader

Memory

Facebook Twitter

The "Double-Checked Locking is Broken" Declaration. Signed by: David Bacon (IBM Research) Joshua Bloch (Javasoft), Jeff Bogda, Cliff Click (Hotspot JVM project), Paul Haahr, Doug Lea, Tom May, Jan-Willem Maessen, Jeremy Manson, John D.

The "Double-Checked Locking is Broken" Declaration

Mitchell (jGuru) Kelvin Nilsen, Bill Pugh, Emin Gun Sirer Double-Checked Locking is widely cited and used as an efficient method for implementing lazy initialization in a multithreaded environment. Unfortunately, it will not work reliably in a platform independent way when implemented in Java, without additional synchronization. When implemented in other languages, such as C++, it depends on the memory model of the processor, the reorderings performed by the compiler and the interaction between the compiler and the synchronization library. Since none of these are specified in a language such as C++, little can be said about the situations in which it will work. To first explain the desired behavior, consider the following code: If this code was used in a multithreaded context, many things could go wrong. Memory Analyzer News » Blog Archive » Automated Heap Dump Analysis: Finding Memory Leaks with One Click. Unveiling the java.lang.Out OfMemoryError.

When we encounter a java.lang.OutOfMemoryError, we often find that Java heap dumps, along with other artifacts, are generated by the Java Virtual Machine. If you feel like jumping right into a Java heap dump when you get a java.lang.OutOfMemoryError, don't worry, it's a normal thought. You may be able to discover something serendipitously, but it's not always the best idea to analyze Java heap dumps, depending on the situation you are facing. We first need to investigate the root cause of the java.lang.OutOfMemoryError. Only after the root cause is identified can we decide whether or not to analyze Java heap dumps. What is a java.lang.OutOfMemoryError? A java.lang.OutOfMemoryError is a subclass of java.lang.VirtualMachineError that is thrown when the Java Virtual Machine is broken or has run out of resources that are necessary to continue the operation of the Java Virtual Machine.

Program Counter Register Java Virtual Machine Stack Heap Method Area Runtime Constant Pool Native Method Stack. Java theory and practice: Plugging memory leaks with weak ... For garbage collection (GC) to reclaim objects no longer in use by the program, the logical lifetime of an object (the time that the application will use it) and the actual lifetime of outstanding references to that object must be the same.

Java theory and practice: Plugging memory leaks with weak ...

Most of the time, good software engineering techniques ensure that this happens automatically, without us having to expend a lot of attention on the issue of object lifetime. But every once in a while, we create a reference that holds an object in memory much longer than we expected it to, a situation referred to as unintentional object retention. Memory leaks with global Maps The most common source of unintentional object retention is the use of a Map to associate metadata with transient objects. Let's say you have an object with an intermediate lifetime -- longer than that of the method call that allocated it, but shorter than that of the application -- such as a socket connection from a client.

Listing 1. Back to top Identifying memory leaks. Understanding Weak References. Posted by enicholas on May 4, 2006 at 5:06 PM PDT Some time ago I was interviewing candidates for a Senior Java Engineer position.

Understanding Weak References

Among the many questions I asked was "What can you tell me about weak references? " I wasn't expecting a detailed technical treatise on the subject. I would probably have been satisfied with "Umm... don't they have something to do with garbage collection? " I was instead surprised to find that out of twenty-odd engineers, all of whom had at least five years of Java experience and good qualifications, only two of them even knew that weak references existed, and only one of those two had actual useful knowledge about them.

Now, I'm not suggesting you need to be a weak reference expert to qualify as a decent Java engineer. Strong references First I need to start with a refresher on strong references. StringBuffer buffer = new StringBuffer(); creates a new StringBuffer() and stores a strong reference to it in the variable buffer. Weak references Reference queues.