Search posts, tags, users, and pages
In Mark and Sweep, the referenced objects are marked and unreferenced objects are swept from heap.
Working of Grabage Collector say otherwise.
Can you please provide more details or quote the exact places where the referenced objects are marked and swept?
(Working of Garbage Collector) The garbage collector's operation correctly uses the mark and sweep algorithm. That's the right one.
Please check this:- geeksforgeeks.org/mark-and-sweep-garbage-collecti… Chetan Datta
No, what I mean is to provide the exact location in my article where the referenced objects are marked and swept. Just copy that line and paste it here, and I will correct those places.
Sorry for the delayed response :)
Garbage Collector/Working of Garbage Collector/1st Run of GC
Objects o2 and o5 do not have any references. So mark these two.
"Objects o2 and o5 do not have any references. So mark these two."
this is correct one
At a given timestamp, the created objects o2 and o5 are present, but no variable is pointing to these objects. Hence, the garbage collector marks these two objects and sweeps them away.
geeksforgeeks.org/mark-and-sweep-garbage-collecti…
this one clearly states that, "In the Mark phase, we set the marked bit for all the reachable objects (or the objects which a user can refer to) to 1(true)."
object that are reachable (i.e., referenced one) are marked and those who are not reachable from how could they be marked ??
In this context, marking mean making sure the object is reachable i.e, still referenced in the program.
In the Garbage Collector/Working of Garbage Collector/1st Run of GC/Sweep
I think it should be "Keep the marked objects and sweep the rest to the appropriate survivor space".
Please share the reference/links you referred to write these, maybe that could help in getting on the same page.
Now I understand your point Shubham Kesri
Please let me know if there are any additional changes required in the updated version.
The corrected (updated) Mark and Sweep algorithm is as follows:
First, we delete unreferenced objects that are no longer in use. Mark the surviving referenced objects. Sweep the marked objects to the next survivor level.
I will update the main article shortly. Thank you for taking the time to help me correct the logic!
Hi Chetan Datta, thanks for effort and commitment,
I would frame it in this manner,
"Firstly, we mark the referenced objects in the Mark phase. followed by shifting/copying of the marked objects to appropriate survivor space and Then, the unmarked objects are removed to free up the memory."
For the Mark, Copy & Sweep occurrence sequence, refer - Serial Garbage Collector in codecurated.com/blog/understanding-how-java-garba…
Thanks
Hi Shubham Kesri,
Noted! I'll make the necessary changes and link the references you've quoted here.
Thank you for sharing the resources.
Hi Chetan Datta, any updates ?