Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new object that will be eligible for garbage collection.
Java
MyObject obj = new [1](); obj = null;🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
2fill in blank
mediumComplete the code to explicitly request garbage collection.
Java
System.[1]();🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
3fill in blank
hardFix the error in the code to avoid preventing garbage collection.
Java
MyObject obj = new MyObject();
obj.[1] = obj;🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
4fill in blank
hardFill both blanks to create a weak reference that allows garbage collection.
Java
WeakReference<MyObject> weakRef = new WeakReference<[1]>(obj); obj = [2];
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
5fill in blank
hardFill all three blanks to implement a finalize method that prints a message before garbage collection.
Java
protected void [1]() throws [2] { System.out.[3]("Object is being garbage collected"); }
🎯 Drag options to blanks, or click blank then click option
Attempts:
3 left
