destructor closes resources if still open