0
0
Javaprogramming~15 mins

Garbage collection overview in Java - Interactive Code Practice

Choose your learning style8 modes available
ads_clickPractice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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
AMyObject
BInteger
CString
DObject
Attempts:
3 left
2fill in blank
medium

Complete the code to explicitly request garbage collection.

Java
System.[1]();
🎯 Drag options to blanks, or click blank then click option
ArunFinalization
Bgc
Cexit
DcollectGarbage
Attempts:
3 left
3fill in blank
hard

Fix 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
Athis
BselfReference
Creference
Dparent
Attempts:
3 left
4fill in blank
hard

Fill 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
AMyObject
Bnull
CObject
Dnew MyObject()
Attempts:
3 left
5fill in blank
hard

Fill 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
Afinalize
BThrowable
Cprintln
Dprint
Attempts:
3 left