Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GC Question

 
Suren Babu
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"
 
Aru Ven
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic