Programming Paradigm & Continuations
The concept of asynchronous programming inherently lends itself to continuation-passing style; if a program is running independently of the main thread, how will the main program know when it has finished? The most common answer to this problem is to implement continuation-passing style for asynchronous functions. The idea is to pass in the continuation of the program to the asynchronous function, and once the function has completed its process, the result is then passed as an argument into the continuation, and the program can advance. All of this can occur without the program having to halt, since we aren’t waiting for the call to finish to continue running the program, but rather just giving the asynchronous call a set of instructions to perform with its result once it has completed.
The mark and sweep garbage collector is able to navigate through all of the variables defined within the program periodically, and mark all of the values referred to by these variables. This particular algorithm makes sure it recursively check and mark the values and properties of any objects or arrays it finds as well in the hopes of being able to find every variable and value within the program that is still reachable. Therefore, any values or variables that were not marked is considered garbage that can be reclaimed by the collector. The garbage collector then begins to sweep through the program, making sure to deallocate and reclaim any memory it finds that is unmarked and considered to be garbage. It does this by iterating through each value within the program’s environment, deallocating any that it finds to be unmarked.