Implemented a garbage collector for hierarchical resources