Вы находитесь на странице: 1из 14

EAD PRESENTATION

Garbage Collection

Group Members:
BCSF13M001
BCSF13M034
BCSF13M039
BCSF13M049
BCSF13M052

Presentation video link:


https://www.youtube.com/watch?v=ifgR3wEL3m0&feature=share

Multiple Choice Questions

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.

Garbage collector never invoked in methodA()

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.

After the start() method completes


When the instance running this code is made eligible for garbage collection.

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 */

X2 x3 = new X2(); /* Line 7 */


x2.x = x3;
x3.x = x2;
x2 = new X2();
x3 = x2; /* Line 11 */
doComplexStuff();
}
}
after line 11 runs, how many objects are eligible for garbage collection?
A.
0
B.
1
C.
2
D.
3
8. What allows the programmer to destroy an object x?
A.
B.
C.
D.

x.delete()
x.finalize()
Runtime.getRuntime().gc()
Only the garbage collection system can destroy an object.

9. Which statement is true?


A.
B.
C.
D.

Programs will not run out of memory.


Objects that will never again be used are eligible for garbage collection.
Objects that are referred to by other objects will never be garbage collected.
Objects that can be reached from a live thread will never be garbage collected.

10. Which statement is true?


A.
All objects that are eligible for garbage collection will be garbage collected by the
garbage collector.
B.
Objects with at least one reference will never be garbage collected.
C.
Objects from a class with the finalize() method overridden will never be garbage
collected.
D.
Objects instantiated within anonymous inner classes are placed in the garbage
collectible heap.
11. Which statement is true?
A.
Memory is reclaimed by calling Runtime.gc().
B.
Objects are not collected if they are accessible from live threads.
C.
An OutOfMemory error is only thrown if a single block of memory cannot be found that
is large enough for a particular requirement.
D.
Objects that have finalize() methods always have their finalize() methods called before
the program ends.

12. Which statement is true?


A.
B.
C.
D.

Calling Runtime.gc() will cause eligible objects to be garbage collected.


The garbage collector uses a mark and sweep algorithm.
If an object can be accessed from a live thread, it can't be garbage collected.
If object 1 refers to object 2, then object 2 can't be garbage collected.

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

20. How garbage collection deals with circular references ?


a) Circular referencing issue happens when two objects refer each other
b) Circular referencing issue happens when an object delete the other
c) Circular referencing issue happens when an object is created on heap
d) none of these
21. What will you do to prevent the garbage collector from calling Object.Finalize on an object
that does not require it?
a) GC.SuppressDispose() method
b) GC.SuppressFinalize() method
c) Runtime.getRuntime().gc()
d) Both a and b
22. Where Destructors Can not be defined?
a) in structs
b) in class
c)none of these
23. destructor, Dispose, Finalize - How they relate to each other?
a) These are used to release unmanaged resources
b) They are used to consume unmanaged resources
c) Resource Allocation
d)None
24. If i have 100 objects in my application are out of scope.when first time garbage collected
how many objects memory reference are free?
a) All the objects are freed
b) First object will be freed
c) Last object will be freed
d) none
25. Which of the following is true ?
a) The Dispose method is called automatically by the runtime and the Finalize method is called
by the programmer
b) The Finalize method is called automatically by the runtime and the Dispose method is called
by the programmer
c) None
26. Which of the following statements are TRUE about the .NET CLR?
1. It provides a language-neutral development & execution environment.

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

27. Which of the following statements is correct about Managed Code?


A.

Managed code is the code that is compiled by the JIT compilers.

B.

Managed code is the code where resources are Garbage Collected.

C.

Managed code is the code that runs on top of Windows.

D.

Managed code is the code that is written to target the services of the CLR.

E.

Managed code is the code that can run on top of Linux.

28. What is garbage collection in the context of Java?


A.
B.
C.
D.
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.

Common Language Infrastructure

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.

Freeing memory on the stack.


Avoiding memory leaks.
Freeing memory occupied by unreferenced objects.
Closing unclosed database collections.

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.

All of the above

32. Which part of the memory is involved in Garbage Collection?

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.

The program crashes

B.

Nothing happens

C.

The program terminates

D.

The exception will be ignored and the garbage collection (finalization) of that object
terminates.

35. Way to call garbage collector?


A.

System.gc()

B.

Runtime.getRuntime().gc()

C.

None of Above

D.

Both A and B

36. How to enable/disable call of finalize() method of exit of the application


A.

Runtime.getRuntime().runFinalizersOnExit(boolean value)

B.

Runtime.getRuntime().runFinalizersOnExit(int value)

C.

Runtime.getRuntime().runFinalizersOnExit(string status)

D.

None of above

37. How many generations are there of garbage collector?


A.

B.

C.

D.

None of above

38. What function garbage collector calls to reserve memory?


A.

VirtualAlloc

B.

VirtualFree

C.

VirtualReserve

D.

None of above

39. Conditions for garbage collection are?


A.

The system has low physical memory.

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.

Garbage collection handles

C.

Static data

D.

All of above

41. Garbage collector manages


A.

Managed code

B.

Unmanaged code

C.

Both A and B

D.

None of above

42. Garbage collection can be


A.

Concurrent

B.

Non-Concurrent

C.

Both A and B

D.

None of above

43. How can we overcome the destructor problem ?


A.

By implementing Disposable interface

B.

By implementing Idisposable interface

C.

By inheriting Didposable class

D.

By inheriting Idisposable class

44. Which of the following phase is involved in garbage collection?


A.

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

45. Which of the following are the limitations of finalizers?


A.
The finalizers of two objects are not guaranteed to run in any specific order, even if one
object refers to the other
B.
The thread on which the finalizer is run is unspecified
C.
Finalize cannot be called on resurrected objects during garbage collection
D.

All of above

46. Where is the clean up code for unmanaged code is written?


A.

In base class

B.

In destructor

C.

In the class

D.

None of above

47. Which of the following is not the technique of garbage collection?


A.

Tracing

B.

Compacting

C.

Copying

D.

Managing

48. Which of the following is not the advantage of garbage collection?


A.

It removes dangling pointer bugs

B.

It removes double free bugs

C.

It prevents memory leaks

D.

Increased performance

49. When garbage collector runs


A.

When system is low in memory

B.

Memory is too much fragmented

C.

After quanta of allocation

D.

All of above

50. Finalization can be called in which of the following cases?


A.

Generation 0 is full

B.

Explicitly call static method GC.Collect

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

Вам также может понравиться