Memory Tuning
This lesson talks about the common memory issues faced when running Java programs.
We'll cover the following...
Question # 1
What are some of the steps you’ll take to improve the memory footprint of a Java application?
Limiting the scope of local variables. Each time the top scope from the stack is popped up, the references from that scope are lost, and this could make objects eligible for garbage collection.
Explicitly set variable references to
null
when not needed. This will make objects eligible for garbage collection.Avoid finalizers. They slow down program performance and do not guarantee anything.
Do not use strong references where weak or soft references apply. The most common memory pitfalls are caching scenarios, when data is held in memory even if it might not be needed.
JVM can be configured based on application requirements. There are a number of knobs that one can use to tune and tweak the memory performance. For instance:
-Xms
specifies the initial heap size-Xmx
specifies the maximum heap size ...