Just looked closer, and the best way is definitely to use the special HashMap and cleaner that are used in DAGScheduler.