aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes GC Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "GC Question" Watch "GC Question" New topic
Author

GC Question

Suren Babu
Greenhorn

Joined: Oct 23, 2000
Posts: 27
Is it guaranteed that when the GC runs it releases the memory allocated by an object.
One if the mock exam is saying yes...
Here is the question...
11. Which statements about garbage collection are true?
A) The garbage collector runs in low memory situations
B) You can run the garbage collector when ever you want.
C) When it runs, it releases the memory allocated by an object.
D) Garbage collector immediately runs when you set the references to null.
The answers given by the site is.. AC
Could somebody put more highlight on this..
Thanks
sunilkumar ssuparasmul
Ranch Hand

Joined: Dec 13, 2000
Posts: 142
THe garbage collector is alow priority thread , but it is not actually a low priority when it comes 2 release resoueces which r no longer used. what do i mean is For eg imagine 2 objects which are eligible for GC and also some other high priority is running then in this case the GC will run even it is low priority , if it is running short of memory.

U can check whether the garbage collector has released memory by doing
System.out.println(Runtime.getRuntime().freeMemory());
before and after setting u r object=null i.e eligible for garbage collection .

------------------
"Winners don't do different things
They do things differently"


"Winners don't do different things<br /> They do things differently"
Aru Ven
Ranch Hand

Joined: Sep 28, 2000
Posts: 199
Here is what I think...... Correct me if I'm wrong.
Which statements about garbage collection are true?
A) The garbage collector runs in low memory situations
- False. There is no guarantee when it wil run. Gc is System dependent.
B) You can run the garbage collector when ever you want.
- calling System.gc() or Runtime.getRunTime().gc() suggests GC, but again it all depends on the JVM.
I really donno whether I should mark this "true" bcoz
System.gc() or Runtime.getRunTime().gc() methods can be called.
Or should I mark it "false" bcoz I can suggest GC by calling them but can't FORCE GC.
C) When it runs, it releases the memory allocated by an object.
- true

D) Garbage collector immediately runs when you set the references to null.
- False. Not always. Remember it is System dependent.
Aruna
 
 
subject: GC Question