Automatic finalization of derived types

Not a solution per se, but as a design consideration it may be worthwhile to consider a “method” (TBP) to clone:

block
   type(resource_owner) :: owner_copy
   call owner%clone( owner_copy ) !<-- the cloning method does the needful with the "data" (C array, etc.)
   ..
   ! Exit from block "cleans" up the clone
end block
1 Like