Dynamic Memory Allocation


With C, you can define the size of an array when the array is declared. Using pointers, you can also determine the size and dynamically allocate memory for an array at runtime. This can be useful if the required size for the array may vary from run to run in that you don't have to worry about declaring a really large array to cover all possibilities. The downside to dynamic memory allocation is that it is up to the programmer to properly allocate and deallocate the dynamic memory. If memory is not properly deallocated, you can create the dreaded memory leak.

Java does not support explicit dynamic memory allocation and deallocation because a sophisticated memory management system is part of the JVM that executes Java programs. As part of the memory management system, Java uses a mechanism known as the garbage collector that periodically monitors a Java program while it is running. Whenever a variable goes out of scope it is eligible to be garbage collected, meaning that memory assigned to the variable is deallocated and made available for use by some other part of the program. A Java programmer never has to worry about manually deallocating memory.



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