Reputation: 1051
I wrote a code, wich uses a huge amount of memory, so I'm monitoring it to the output. The result is kinda interesting, can someone explain me why is my free memory lowers and than increases, though I'm allocating object continuously, and why does it stack at a value?
Here's my monitoring code:
Thread th = new Thread(new Runnable() {
@Override
public void run() {
while(true){
System.out.println("" + (Runtime.getRuntime().freeMemory()/1024));
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
Logger.getLogger(FaAlgoritmus.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
th.start();
And the result:
42454
49666
109869
76995
39779
125981
89814
191056
137835
142766
121279
50221
130072
75460
143199
88164
145557
75224
27234
136953
87933
34991
151526
99113
47005
163787
56278
44491
44491
44491
44491
44491
44491
44491
44491
44491
44489
44489
44489
Upvotes: 1
Views: 91
Reputation: 500673
can someone xplain me why is my free mem lowers and than increases
New objects are allocated in the Eden space. Once you run out of Eden space, a minor garbage collector kicks in and gets rid of unreferenced objects (promoting all referenced objects into one of the survivor spaces). Typically, this would lead to a jump in the amount of free memory.
Upvotes: 3