Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Forums
Register
Login
Java
»
Beginning Java
How many Objects are garbage collected?
Thomas Markl
,
Ranch Hand
Nov 24, 2002 09:00:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
class GarbageCollector1 { public static void main ( String ka [] ) { Integer i1 = new Integer(1); Integer i2 = new Integer(2); i1 = null; //object v1 "new Integer(1)" is eligible for gc but //object reference v1 ("Integer i1" still exists //but with value "null" instead of "Integer(1)". i2 = i1; //Objects i2 is now eligable for gc as it is //dereferenced by "Integer i2". i2 is not pointing //to i1 object which has no reference //=> Therefore i2=i1 is same as i2 = null; System.out.println( "i2 == i1: "+ (i2 == i1) ); System.out.println("i1 ="+i1+ " i2 ="+i2); } }
C:\Java\EigeneJavaProgramme>
java
GarbageCollector1
i2 == i1: true
i1 =null i2 =null
I think 2 objects (Integer(1) and Integer(2) are eligable for gc.
Is it correct?
Bert Bates
,
author
staff
Nov 24, 2002 15:53:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
Thomas -
unless you've buried something tricky in there somewhere, you are right - two objects are g.c. eligible.
Post by:
autobot
Attractive, successful people love this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
This thread has been viewed 847 times.
Similar Threads
What is the diff. b/w "==" and ".equals( )" Operators
Accessing Weakly Referenced Objects
Clarification on Garbage Collection
Object References & GC
More...
All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:56:01
.