Performance comparison(in the terms of heap size) whether to use collection object or Java transfer object

StackOverflow https://stackoverflow.com/questions/23602973

  •  20-07-2023
  •  | 
  •  

Question

Which one having less performance issue (in the terms of heap size).

Whether I create HasMap<key,value> to get data according to it's key value or shall I use transfer object and using its setters & getters method retrieve the data.

Here I have to create almost 1000 hashmap or transfer object at a time .

Was it helpful?

Solution

Transfer object is much more economical, try this test

public class Test1 {
    int i1 = 1;
    int i2 = 1;

    public static void main(String[] args) throws Exception {
        Runtime rt = Runtime.getRuntime();
        long m0 = rt.totalMemory() - rt.freeMemory();
        Map m = new HashMap();
        m.put("i1", 1);
        m.put("i2", 1);
        //Test1 t1 = new Test1();  
        long m1 = rt.totalMemory() - rt.freeMemory();
        System.out.println(m1 - m0);
    }
}

it shows used memory, run it with -XX:-UseTLAB JVM arg to get correct results

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top