About Question com.enthuware.ets.scjp.v6.2.561 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

About Question com.enthuware.ets.scjp.v6.2.561 :

Post by ETS User »

public void process(int count) //line 1
{
for ( int i = 1; i < count; i++ ) //line 2
{
Object temp = new Object(); // line 3
}
// Line 4
}

My thinking was 5 objects are available for gc after line 4. 4 from temp and 1 from variable i.

your answer does to consider the scope for i, please clarify

admin
Site Admin
Posts: 10398
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.561 :

Post by admin »

variable i is a primitive type. They are not even objects. Primitives are never GCed.

Guest

Re: About Question com.enthuware.ets.scjp.v6.2.561 :

Post by Guest »

ETS User wrote:public void process(int count) //line 1
{
for ( int i = 1; i < count; i++ ) //line 2
{
Object temp = new Object(); // line 3
}
// Line 4
}

My thinking was 5 objects are available for gc after line 4. 4 from temp and 1 from variable i.

your answer does to consider the scope for i, please clarify

I was thinking the same thing. Thanks for the clarification!

ETS User

Re: About Question com.enthuware.ets.scjp.v6.2.561 :

Post by ETS User »

I think correct answer here is 0, because all the references are active and not nulled. Particularly if keep in mind that even if all references and references are nulled, its not a guarantee that gc will run...

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests