HiRecently at an interview I was asked the following question:Create a hashtable A, assign key value pairs to it and then set A to null. Will it be garbage collected?Please reply.

Questions by deepti_bellubbi

Showing Answers 1 - 9 of 9 Answers

tommckinley

  • Feb 15th, 2007
 

The hashtable object A will be garbage collected, but your key or value objects may still exist if they were assigned to a variable still in scope.

  Was this answer useful?  Yes

Yes the hashtable would be avaliable for garbage collection BUT when actually is would be collected that would depend on JVM garbage collection cycle.

vinny

  Was this answer useful?  Yes

Objects which have null references are garbage collected ..

But you can just request the garbage collector algo to start..
you cannot command it..
so when it would be collected is not known..
Also, a null reference attached to object is called as weak reference
And weak references are garbage collected.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions