public class Test { Test(int n, String noName, Double d, long beta){ } public static void main(String[]arg){ Test test = new Test(2,"name",2.0,15124505154L); } } |
2 answers
In this case, the memory allocated for the literals passed in the arguments of the constructor will be cleared after the constructor finishes its work.
The object does not contain fields and the size of its memory will not depend on the generated literals in the constructor.
Only the object with a string literal will be stored in memory (except for the main Test object), but since it will be taken from the string pool during the next use, there will be no memory leaks.
|
No, of course. If there are no more references to these objects, the garbage collector will eat them, as usual.
|