Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

On gc  RSS feed

 
amit bhadre
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how gc() method will come to know that Object is no longer usable.That is how it identifies tha objects in jvm, which mechanism is used?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This has nothing to do with Threads; moving to Java in General (Beginner).
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ways to implement GC, but most modern implementations use some variation of the "mark and sweep" algorithm. Basically, the collector starts from all static member variables and the stack frames of all threads. It "marks" every object to which it finds a reference. Then it looks at the member variables of all those objects, and marks the referenced objects. And then the members of those, etc. Eventually, all reachable objects are marked. Then the GC looks through memory for unmarked objects; those are the unreachable ones that can be collected.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!