I've found a code which measures memory before and after instantiating lotsa fatty classes
/**
* Memory Storage Test (v2.01)
* by Jon Skeet (2008/Oct)
* mod GoToLoop
*
* https://forum.processing.org/topic/when-to-use-functions
*
* http://stackoverflow.com/questions/229886/size-of-a-byte-in-memory-java
* http://stackoverflow.com/questions/383551/what-is-the-size-of-a-boolean-variable-in-java
*/
static final class LotsOfBooleans { // 96 boolean variables
boolean a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, aa, ab, ac, ad, ae, af;
boolean b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ba, bb, bc, bd, be, bf;
boolean c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, ca, cb, cc, cd, ce, cf;
boolean d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, da, db, dc, dd, de, df;
boolean e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, ea, eb, ec, ed, ee, ef;
boolean f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, fa, fb, fc, fd, fe, ff;
}
static final class LotsOfBytes { // 96 byte variables
byte a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, aa, ab, ac, ad, ae, af;
byte b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ba, bb, bc, bd, be, bf;
byte c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, ca, cb, cc, cd, ce, cf;
byte d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, da, db, dc, dd, de, df;
byte e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, ea, eb, ec, ed, ee, ef;
byte f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, fa, fb, fc, fd, fe, ff;
}
static final class LotsOfInts { // 96 int variables (96*4 = 384 bytes)
int a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, aa, ab, ac, ad, ae, af;
int b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, ba, bb, bc, bd, be, bf;
int c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, ca, cb, cc, cd, ce, cf;
int d0, d1, d2, d3, d4, d5, d6, d7, d8, d9, da, db, dc, dd, de, df;
int e0, e1, e2, e3, e4, e5, e6, e7, e8, e9, ea, eb, ec, ed, ee, ef;
int f0, f1, f2, f3, f4, f5, f6, f7, f8, f9, fa, fb, fc, fd, fe, ff;
}
static final int SIZE = 1024*1024;
static long startMem, endMem;
final void setup() {
final LotsOfBooleans[] first = new LotsOfBooleans[SIZE];
final LotsOfBytes[] second = new LotsOfBytes[SIZE];
final LotsOfInts[] third = new LotsOfInts[SIZE];
/////////////////////////////////////////////////////////////////////////////
System.gc();
startMem = getMemory();
for (int i = 0; i != SIZE; first[i++] = new LotsOfBooleans());
System.gc();
endMem = getMemory();
println("Size for LotsOfBooleans: " + (endMem - startMem));
println("Average size: " + (endMem - startMem) / SIZE);
/////////////////////////////////////////////////////////////////////////////
System.gc();
startMem = getMemory();
for (int i = 0; i != SIZE; second[i++] = new LotsOfBytes());
System.gc();
endMem = getMemory();
println("\nSize for LotsOfBytes: " + (endMem - startMem));
println("Average size: " + (endMem - startMem) / SIZE);
/////////////////////////////////////////////////////////////////////////////
System.gc();
startMem = getMemory();
for (int i = 0; i != SIZE; third[i++] = new LotsOfInts());
System.gc();
endMem = getMemory();
println("\nSize for LotsOfInts: " + (endMem - startMem));
println("Average size: " + (endMem - startMem) / SIZE);
/////////////////////////////////////////////////////////////////////////////
exit();
}
static final long getMemory() {
final Runtime rt = Runtime.getRuntime();
return rt.totalMemory() - rt.freeMemory();
}