Java vs C++ Memory Management Features Comparison

Java vs C++

Java vs C++

There exist great differences between Java vs C++ memory management. One of the strengths of the Java platform is that performs automatic memory management; thereby developers do not need to worry about the complexity of explicit memory management. On the other hand, C++ provides developers with control over memory allocation and de-allocation using pointers, which indicate the memory can be use more efficiently and that performance programs can be optimized. However, Sun Microsystem (2006, p3) states that this can lead to serious executions errors. As a result, a large proportion of developers time is often spend debugging and trying to correct such error. In addition, there is nothing that restrains C++ developers from accessing OS data, or even executable code that resides in the memory (Vivanco & Pizzi 2005, p241).

Sun Microsystem (2006, p3) states that the common problems languages with explicit memory management such as C++ are dandling references and space leaks. Dandling reference means that is possible to deallocate the space used by an object to which other object still has reference. If the other object tried to access the original object and the space has been relocated to a new object, the result is unpredictable. Space leaks occur when memory is allocated and not longer referenced but is not released.

Java and other modern object-orientated languages have taken the approach to make programming easier and more robust. To do so, Java has automatic management program called garbage collector that avoid the dandling reference problem, because an object that is still referenced somewhere will never be garbage collected. It also solves the space leak problem since it automatically frees all memory no longer referenced. Sun Microsystem (2006, p4) states that the garbage collector enables increased abstraction of interfaces and more reliable code. Vivanco and Pizzi (2005, p252) argue that this built in feature makes Java, as a development environment, more cohesive, extensible and maintainable system than C++.


Vivanco, RA & Pizzi, NJ 2005 ‘Scientific computing with Java and C++: a case study using functional magnetic resonance neuroimages’, Software: Practice and Experience, vol. 35, no. 3, pp. 237-254.

Sun Microsytems 2006,  ‘Memory Management in the Java HotSpotTM Virtual Machine’, viewed 13 November 2013,


One thought on “Java vs C++ Memory Management Features Comparison

  1. david

    All from perspective of “java” advantages. Disadvantages: it takes time for OS to manage memory, OS will tend to use extra ram, and in some situations memory can actually leak.


Leave a Reply

Your email address will not be published. Required fields are marked *