CodeGym /Courses /Java Collections /Tasks | Level 4 | Lesson 4

Tasks | Level 4 | Lesson 4

Java Collections
Level 4 , Lesson 4
Available

"What, do you miss me? Here you are:"

8
Task
Java Collections, level 4, lesson 4
Locked
Soft references
Soft references
Comments (1)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Hoist Level 17, San Diego, United States
8 January 2024
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”.