Mastering Java: The Ultimate 2025 All-In-One Quiz to Excel in 'Thinking in Java

Question: 1 / 510

What happens to object storage when an object is no longer referenced and becomes garbage collected?

Memory is immediately freed.

Storage is marked and compacted at next garbage collection.

When an object is no longer referenced and becomes garbage collected, the storage for the object is marked and will be compacted during the next garbage collection. This means that the storage space previously occupied by the object will be reused for future objects, resulting in more efficient use of memory. Option A is incorrect because memory is not immediately freed, as garbage collection occurs at a later time. Option C is incorrect because finalize() is called before garbage collection, but it does not necessarily result in immediate memory release. Option D is incorrect because data is only overwritten for security purposes when the storage is reused, not when an object becomes garbage collected.

Get further explanation with Examzify DeepDiveBeta

finalize() is called.

Data is overwritten for security.

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy