my code is here =>
class PointHolder {
private Point point;
public PointHolder(Point point) {
this.point = point;
}
//getter
}
class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
//getter setter
}
public class Escape {
public static void main(String[] args) {
for (int i = 0; i < 20000; i++) {
test4(i);
}
}
static int foo;
public static void test4(int x) {
PointHolder pointHolder = new PointHolder(new Point(x + 2, 42));
foo = pointHolder.getPoint().getX();
}
}
use the jitwatch, i could see the pointHolder is not been allocated, but new Point(x+2, 42)
is still been allocated.
i could not figure out why