Академический Документы
Профессиональный Документы
Культура Документы
Garbage Collection
Group Members:
BCSF13M001
BCSF13M034
BCSF13M039
BCSF13M049
BCSF13M052
1. void start() {
A a = new A();
B b = new B();
a.s(b);
b = null; /* Line 5 */
a = null; /* Line 6 */
System.out.println("start completed"); /* Line 7 */
}
When is the B object, created in line 3, eligible for garbage collection?
A.
after line 5
B.
after line 6
C.
after line 7
D.
There is no way to be absolutely certain.
2. class HappyGarbage01
{
public static void main(String args[])
{
HappyGarbage01 h = new HappyGarbage01();
h.methodA(); /* Line 6 */
}
Object methodA()
{
Object obj1 = new Object();
Object [] obj2 = new Object[1];
obj2[0] = obj1;
obj1 = null;
return obj2[0];
}
}
Where will be the most chance of the garbage collector being invoked?
A.
After line 9
B.
After line 10
C.
After line 11
D.
3. class Bar { }
class Test
{
Bar doBar()
{
Bar b = new Bar(); /* Line 6 */
return b; /* Line 7 */
}
public static void main (String args[])
{
Test t = new Test(); /* Line 11 */
Bar newBar = t.doBar(); /* Line 12 */
System.out.println("newBar");
newBar = new Bar(); /* Line 14 */
System.out.println("finishing"); /* Line 15 */
}
}
At what point is the Bar object, created on line 6, eligible for garbage collection?
A.
after line 12
B.
after line 14
C.
after line 7, when doBar() completes
D.
after line 15, when main() completes
4. class Test
{
private Demo d;
void start()
{
d = new Demo();
this.takeDemo(d); /* Line 7 */
} /* Line 8 */
void takeDemo(Demo demo)
{
demo = null;
demo = new Demo();
}
}
When is the Demo object eligible for garbage collection?
A.
After line 7
B.
After line 8
C.
D.
5. public class X
{
public static void main(String [] args)
{
X x = new X();
X x2 = m1(x); /* Line 6 */
X x4 = new X();
x2 = x4; /* Line 8 */
doComplexStuff();
}
static X m1(X mx)
{
mx = new X();
return mx;
}
}
After line 8 runs. how many objects are eligible for garbage collection?
A.
0
B.
1
C.
2
D.
3
6. public Object m()
{
Object o = new Float(3.14F);
Object [] oa = new Object[l];
oa[0] = o; /* Line 5 */
o = null; /* Line 6 */
oa[0] = null; /* Line 7 */
return o; /* Line 8 */
}
When is the Float object, created in line 3, eligible for garbage collection?
A.
just after line 5
B.
just after line 6
C.
just after line 7
D.
just after line 8
7. class X2
{
public X2 x;
public static void main(String [] args)
{
X2 x2 = new X2(); /* Line 6 */
x.delete()
x.finalize()
Runtime.getRuntime().gc()
Only the garbage collection system can destroy an object.
13. Which operator is used by Java run time implementations to free the memory of an object
when it is no longer needed?
a) delete
b) free
c) new
d) None of the mentioned
14. Which function is used to perform some action when the object is to be destroyed?
a) finalize()
b) delete()
c) main()
d) None of the mentioned
15. Is it possible to force garbage collection to run?
a) Yes
b)No
16.How to force garbage collection to run?
a) GC.Collect()
b) GC.Select()
c) GC.Run()
17. What is the method for releasing resources that an object acquires?
a) Dispose()
b) Release()
c) Free()
d) Available()
18. Is it possible to invoke Garbage Collector explicitly?
a) Yes
b) No
19. Which of the following does not constitute the benefits of CLR?
a. Ability to use components developed in different language
b. Garbage collection
c.
d.
IDL (Interface Definition Language) use is promoted by restricting self describing objects
Ability to compile once, and run on any CPU
2. It ensures that an application would not be able to access memory that it is not authorized to
access.
3. It provides services to run "managed" applications.
4. The resources are garbage collected.
5. It provides services to run "unmanaged" applications.
A.
Only 1 and 2
B.
Only 1, 2 and 4
C.
1, 2, 3, 4
D.
Only 4 and 5
E.
Only 3 and 4
B.
C.
D.
Managed code is the code that is written to target the services of the CLR.
E.
The operating system periodically deletes all of the java files available on the system.
Any package imported in a program and not used is automatically deleted
When all references to an object are gone, the memory used by the object is
automatically reclaimed
The JVM checks the output of any Java program and deletes anything that doesn't make
sense.
Janitors working for Sun MicroSystems are required to throw away any Microsoft
documentation found in the employees' offices.
29. Which of the following .NET components can be used to remove unused references from
the managed heap?
A.
B.
CLR
C.
Garbage Collector
D.
Class Loader
E.
CTS
30. Which of the following jobs are NOT performed by Garbage Collector?
1.
2.
3.
4.
5. unclosed files.
A.
1, 2, 3
B.
3, 5
C.
1, 4, 5
D.
3, 4
31. Which of the following jobs are done by Common Language Runtime?
1. It provides core services such as memory management, thread management, and remoting.
2. It enforces strict type safety.
3. It provides Code Access Security.
4. It provides Garbage Collection Services.
A.
Only 1 and 2
B.
Only 3, 4
C.
Only 1, 3 and 4
D.
Only 2, 3 and 4
E.
A.
Stack
B.
Heap
C.
None of above
D.
Both A and B
33. How many times does the garbage collector calls the finalize() method for an object?
A.
Once
B.
Twice
C.
Thrice
34. What happens if an uncaught exception is thrown from during the execution of the
finalize() method of an object?
A.
B.
Nothing happens
C.
D.
The exception will be ignored and the garbage collection (finalization) of that object
terminates.
System.gc()
B.
Runtime.getRuntime().gc()
C.
None of Above
D.
Both A and B
Runtime.getRuntime().runFinalizersOnExit(boolean value)
B.
Runtime.getRuntime().runFinalizersOnExit(int value)
C.
Runtime.getRuntime().runFinalizersOnExit(string status)
D.
None of above
B.
C.
D.
None of above
VirtualAlloc
B.
VirtualFree
C.
VirtualReserve
D.
None of above
B.
The memory that is used by allocated objects on the managed heap surpasses an
acceptable threshold. This threshold is continuously adjusted as the process runs.
C.
The GC.Collect method is called. In almost all cases, you do not have to call this method,
because the garbage collector runs continuously. This method is primarily used for
unique situations and testing.
D.
All of above
40. Which of the following information the garbage collector uses to determine whether
objects are live
A.
Stack roots
B.
C.
Static data
D.
All of above
Managed code
B.
Unmanaged code
C.
Both A and B
D.
None of above
Concurrent
B.
Non-Concurrent
C.
Both A and B
D.
None of above
B.
C.
D.
A marking phase that finds and creates a list of all live objects.
B.
A relocating phase that updates the references to the objects that will be compacted.
C.
A compacting phase that reclaims the space occupied by the dead objects and compacts
the surviving objects.
D.
All of above
All of above
In base class
B.
In destructor
C.
In the class
D.
None of above
Tracing
B.
Compacting
C.
Copying
D.
Managing
B.
C.
D.
Increased performance
B.
C.
D.
All of above
Generation 0 is full
B.
C.
Both A and B
D.
None of above
References:
http://java-questions.com/garbagecollection-interview-questions.html
http://www.careerride.com/Dot-Net-force-garbage-collection.aspx
http://www.indiabix.com/java-programming/garbage-collections/
http://www.logicguns.com/java-objective-questions/?page=2&topic=garbage-collection
http://seattlecentral.edu/faculty/flepeint/javaclass/quiz1solt.PDF
http://cs-mcqs.blogspot.com/2013/01/solved-mcqs-dot-net-frame-work.html
https://msdn.microsoft.com/en-us/library/ee787088(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/0xy59wtx(v=vs.110).aspx
http://csharpinterviewfaq.blogspot.com/2010/01/what-is-garbage-collectiongc.html
http://www.careerride.com/NET-Garbage-collection.aspx
http://www.sanfoundry.com/java-mcqs-constructors-garbage-collection/
http://www.indiabix.com/java-programming/garbage-collections/021001
http://www.c-sharpcorner.com/forums/c-sharp-net-fundamental-answers-needed-for-mcq