add scope(exit) to free resource in metadata