Tasks | Level 4 | Lesson 4
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Hoist
8 January, 02:38
An out-of-memory exception has occurred
Finalized
Done
It took 19 s
Bye-bye, George !
// the SoftReference to the Monkey object is created - means that the Monkey object can be garbage collected if the JVM is running low on memory, but will be kept as long as possible. Class is public and static, meaning it can be accessed from anywhere and does not require an instance of the outer Solution class to be created.
The finalize() method in the Monkey class is called by the garbage collector before the object is destroyed. This method sets Helper.isFinalized to true and prints a goodbye message.
The Helper class provides several utility methods for starting a timer, calling the garbage collector, consuming heap space, and finishing the program.
The main method creates a Monkey, calls the garbage collector, sets the Monkey reference to null, calls the garbage collector again, consumes heap space, and checks if the Monkey has been finalized.
// If the Monkey has been finalized, it prints “Finalized”.
0