Will the following code be Garbage Collected before the class "dies"?

Posted by devoured elysium on Stack Overflow See other posts from Stack Overflow or by devoured elysium
Published on 2010-04-04T03:03:40Z Indexed on 2010/04/04 3:13 UTC
Read the original article Hit count: 389

Filed under:
|
|
|

Let's say we have the following code in a class:

//class code
TextBox t = new TextBox();
ListBox l = new ListBox();

We have then two possible situations:

In the first, we declare qem1 as a class variable(or attribute, as they call it in the Java World):

//class variable
QuickEntryMediator qem1 = new QuickEntryMediator(t,l);

In the second, we declare it inside a method:

//method variable
QuickEntryMediator qem2 = new QuickEntryMediator(t,l);

So, I'd say qem1 would never be Garbage Collected before the class goes out of scope while in the qem2 might be Garbage Collected at any time after the method in which it resides dies. Is this true?

I am looking for answers for both C#(.net) and Java, as am I am not sure both GC's work in the same fashion!

Thanks

© Stack Overflow or respective owner

Related posts about java

Related posts about .NET