Hi,
I have confusion about following two cases
How many objects will be eligible for GC just after the method returns?
public void compute(Object p)
{
Object a = new Object();
int x = 100;
String str = "abc";
}
When does the String object “ hi ” instantiated on line 2 become eligible for garbage collection?
public class Hello {
String greeting = “hi”;
public static void main(String [] args) {
Hello h = new Hello();
h.greeting = null;
System.gc();
return;
}
}
The answer to first is
"abc" is a string literal which goes to the string pool and is not GCed.
I want to clarify whether the same holds for second also. Will the local string and instance member string both not be GCEed?
GC of Method Local String and Instance Local String
Moderator: admin
-
- Posts: 14
- Joined: Sat Jan 19, 2013 8:42 am
- Contact:
-
- Site Admin
- Posts: 10066
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: GC of Method Local String and Instance Local String
Yes, neither of them will be GCed.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 201 guests