This handle_cast/2 may be called multiple times, always updating the same key. The issue is that compute() uses a lot of memory (to be more precise, it points to data allocated on the GPU) and therefore we want to Garbage Collect whatever is on key before we call compute() again. In other words, we want to do this:
It used to be necessary to do tricks like that to ensure that garbage was removed, especially in JAM (Joe’s Abstract Machine) but also to a lesser degree in early versions of BEAM.
Modern BEAM is very careful to never keep a reference to a term that will not be used again. Therefore, in @josevalim’s original code, no reference to the original map is kept when erlang:garbage_collect/0 is called.