Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8102903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:22:07+00:00 2026-06-05T23:22:07+00:00

I’ve been studying a little about garbage collection, mostly applied to server-side / real-time

  • 0

I’ve been studying a little about garbage collection, mostly applied to server-side / real-time applications, and I’ve started to sketch an algorithm with which it would be possible to have an asynchronous garbage collection system. Since I’m starting on this topic now, so I don’t know very deeply about gc algorithms, I was wondering about the possible pitfalls of an implementation like that. The algorithm is very crude, and with many undefined parts.

Here’s how I thought about it:

  • each thread has its own heap space to manage, and stores a list of pointers it owns that are in use by other threads
    With that, garbage collection works totally asynchronous to the running threads, and:
  • phase 1 start following the threads’ roots and marking all objects reacheable by them. If we get into another thread’s space, we stop following this pointer, and mark this pointer as “in use” on the owner thread
  • after we have marked all regions, we select a region (maybe with most dead references as possible), and start copying its live object references to another space. (it might be the whole thread heap space, but I think it could be too memory-intensive this operation)
  • copying starts with setting with CAS a flag which states that the object is being copied. Any mutable action to be performed on this particular object while that flag is set will spin lock until a new address is set by the gc thread. When copying finishes, a new address is set on the old one, and any mutable reference to be performed on the object will be routed to the new object
  • after updating all references made to those pointers using CAS, the old space is finally freed (no new pointers will be updated with the wrong address, since every mutator will first check to see if the reference has changed locations)

That’s it!

Anyway, I’m quite excited with a possible implementation that doesn’t stops-the-world, and using only fast spin-locks that apply only to the object being copied. But I’d like to know if this is possible to implement, or if there is any possibility of having a dangling pointer somewhere, or memory leaks, or it it’s inneficient, etc. Any info that will contribute to this will be greatly appreciated!

I’m not at all too sure about how e.g. it would handle circular references from different threads. I think this would be handled naturally since we update all hazard pointers the current gc’ed thread has.
There might also be some kind of concurrent access I wasn’t considering.

Thank you!

—- EDIT:
Thanks to Ernest’s contribution, I’m thinking about not using a copying algorithm, but maybe a simple mark & sweep. That’s because we’d need to check every time we access an object’s variable if the pointer has been updated. This seems to me a quite big overhead. Doesn’t it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:22:09+00:00Added an answer on June 5, 2026 at 11:22 pm

    Your ideas are good but I believe there are lots of subtle problems that will require a lot of work to solve and, once solved, you won’t be able to attain competitive throughput performance.

    each thread has its own heap space to manage, and stores a list of pointers it owns that are in use by other threads With that, garbage collection works totally asynchronous to the running threads, and:

    If there is a shared object, which thread owns it? If a concurrent collection has objects added to it from different threads, will there be many inter-heap pointers? How do you handle cycles between heaps?

    phase 1 start following the threads’ roots and marking all objects reacheable by them. If we get into another thread’s space, we stop following this pointer, and mark this pointer as “in use” on the owner thread

    If this is done concurrently with the mutator running, how do you prevent race conditions where the mutators alter the topology to introduce or eliminate inter-heap references while the GC is doing this marking?

    after we have marked all regions, we select a region (maybe with most dead references as possible), and start copying its live object references to another space. (it might be the whole thread heap space, but I think it could be too memory-intensive this operation)

    If this is for multicore, copying will saturate global memory bandwidth and destroy scalability.

    copying starts with setting with CAS a flag which states that the object is being copied. Any mutable action to be performed on this particular object while that flag is set will spin lock until a new address is set by the gc thread. When copying finishes, a new address is set on the old one, and any mutable reference to be performed on the object will be routed to the new object

    Lock-free is tricky. You’re making assumptions about memory models. You may need memory barriers. Looks like you’re just emulating a lock, in which case you’re talking about acquiring and releasing a lock around every write of a reference into the heap which would be prohibitively expensive.

    Spin locks are also bad for concurrency because you’re not only tying up a thread but also burning a core that can no longer do the work that you are waiting on! See the last core slowdown bug in GHC. A wait free solution would use CAS to get the mutator thread to help with the GC work rather than block waiting for another thread to do it.

    after updating all references made to those pointers using CAS, the old space is finally freed (no new pointers will be updated with the wrong address, since every mutator will first check to see if the reference has changed locations)

    Ok.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a reasonable size flat file database of text documents mostly saved in
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.