How to defer resource cleanup when that resource outlives the scope of the surrounding function? How to defer resource cleanup when that resource outlives the scope of the surrounding function? go go

How to defer resource cleanup when that resource outlives the scope of the surrounding function?