Imagine that you don't want your application, or say, a section of your application, to use more than a certain amount of heap memory, such as 40 MB. How can you assert this? In this case, you can configure to execute your applications with -Xmx40m. Here's some example code that adds the same string values as the key/value pair to HashMap and then removes it—by iterating it multiple times (1_000_000 to be precise):
import java.util.*; class EpMap { public static void main(String args[]) { Map<String, String> myMap = new HashMap<String, String>(); int size = 1_000_000; for(int i = 0; i < size; i++) { String java = new String("Java"); String eJavaGuru = new String("eJavaGuru.com"); myMap.put(java, eJavaGuru); ...