Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

GC Question

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"
 
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic