Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Garbage collection isn't generally something that happens periodically as it isn't needed until you get a bunch of new allocations and classically did not happen on some background thread as that's both extremely difficult to pull off and requires threading support in the first place. The simpler way to think about garbage collection is you establish a heap, set a size, and when you run out of space in that heap you run a garbage collection pass during the memory allocation that failed. If you fail to free enough memory, you either kill the program or request a larger heap.


This is the way it is described in the GC Handbook as well.

  New(): 
    ref <- allocate()
    if ref = null
      collect()
      ref <- allocate()
      if ref = null
        error "Out of memory"
    return ref




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: