Memory Management


With C++, the programmer is responsible for memory management for a given program. Memory that is allocated for an object using the new operator must be explicitly deallocated using the delete operator. The delete operation is often performed in a specialized method called a destructor. If you don't properly deallocate memory, you can get the dreaded memory leak.

You don't have to worry about managing memory with Java. A built-in system thread, the garbage collector, is automatically run every so often by the Java runtime. The garbage collector checks all existing objects and releases the resources allocated to any object if there are no longer any references to it. This feature eliminates the possibility of memory leaks that can happen with a C++ program. There are no destructors in Java although a class can declare a finalize() method that can perform some application-specific clean-up operations when it is called.



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net