I have worked with some projects where achieving better performance and reducing memory consumption has been the primary goal. But believe me it has already been hard to control the memory consumption in Java.
This wiki page, says on "Java Program Speed" Java is in some cases equal to C++ on low-level and numeric benchmarks.
These statistics do not really show a major difference in time computation Performance benchmark. However, the memory usage in Java is quite higher than C++, since there is an 8-byte overhead for each object and 12-byte for each array in Java (32-bit; twice as much in 64-bit java) as mentioned in above wiki link.
Now the question is what all measures people take to minimize the memory utilization in Java?
Please note that I am much concerned about memory than performance, since I cannot think of any better ways than "writing better programs" and "correctly tuning memory in JDK"
Set the Heap Size If you reduce the Java heap size by a certain amount you will reduce the memory footprint of the Java process by the same amount. You can however not reduce the Java heap size infinitely. The heap must be at least large enough for all objects that are alive at the same time.
Memory Limit Exceeded Error: It typically occurs when no memory limit has been set. It means that the program is trying to allocate more memory than the memory limit for the particular problem. For Example, if the memory limit is 256 MB, then there is no need to write code that requires more than 256 MB of memory.
Java garbage collection is the process by which Java programs perform automatic memory management. The garbage collector find unreferenced objects and deletes them to free up memory. Java garbage collection is an automatic process. The programmer does not need to explicitly mark objects to be deleted.
Depending on your what you are working on you can benefit from different programming practices such as:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With