I don't think we can assume any compiler optimizations for the sake of exam. Otherwise, results can be different depending on which compiler user chooses. So work through the examples assuming details given only in the Java Language Specification.
Having said that and assuming no compiler optimizations, answer for this question is 5 and as follows. The list of objects/values shows the snapshot of heap after a corresponding statement is executed. (lost) indicates that object doesn't have a valid reference.