I passed the task but on IntelliJ, nothing is displayed when i run the code ...
Any explanations?
Thanks in advance :)
passed task, but nothing displayed?
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
4 January 2021, 15:23solution
There is no guarantee when the JVM will actually do garbage collection. This is all handled internally by some complex algorithm based on how much memory the CPU has, how much memory the program is using, the speed of the CPU, and many other factors. Maybe ten years ago, on a windows XP system, 50000 objects in the computers memory was probably a lot, however today that is quite trivial. Try increasing the amount of objects created to a million, that kicks off the GC on my computer. If that doesn't work try increasing it at 10 million, 100 million, etc.
You could alternatively use this inside your object creation loop:
This activates the garbage collection, though you should not use this in your code other than for testing/debug purposes, and never have it in final code. It will slow the code down quite a bit +2
Jurij Thmsn
4 January 2021, 16:19
Thanks again for your answer and the additional information! Really appreciate it :)
+1