3 ms·
The char or int datatypes do not have their values stored as objects. When you change the value of a char inside a char[] array, that value is directly changed
by RyanZAG 14y ago
The char or int datatypes do not have their values stored as objects. When you change the value of a char inside a char[] array, that value is directly changed in ram.
This will leave the "hello" in ram (subject to GC):
String x = "hello"
x = null;
This will clear the "hello" from ram:
char[] x = new char[]{'h','e','l','l','o'};
x[0] = '0'; x[1] = '0'; ...
This will leave the "hello" in ram (subject to GC):
char[] x = new char[]{'h','e','l','l','o'};
x = null;
- ygra 14y agoThe point was about the garbage collector compacting memory regions, thus moving objects around. If you don't pin your array it could leave "hello" somewhere in memory when it's moved before you zero it.