Closed sebastianbeyer closed 9 years ago
Good find, I added your deallocate commit to the master.
What do you suppose causes this memory leak in the nc_dims routine? I saw that it refers to the line when the names
array is allocated for example. But I cannot see really what the problem would be. Unless Fortran is not robust concerning multiple optional allocatable arguments, or we are doing something wrong... Any thoughts?
Yeah, names
and dims
are allocated, when they are given as optional arguments, but they are never deallocated. And it is impossible to deallocate them in this subroutine, because it it the purpose of this subroutine to set them.
To solve this, one would need another subroutine, that is called after names
and dims
are no longer used and deallocates them. This would be a little bit cleaner, but maybe also confusing. I think this is not really an issue, because the memory that is allocated is so small.
Ok, yes in that case I think it's not something to worry about. '''names''' and '''dims''' as variables defined in the main program, therefore it should be the responsibility of the user to deallocate them, in the same way they would deallocate anything else. But it's easy to overlook them...
While searching for another bug in my code I found this.
nc_dims
is still a little leaky, but I don't know how fix this, since thedims
andnames
are intent out, so we can not handle this in the subroutine. Anyway, we are talking about 100 bytes, so I am not sure if this is really worth the effort. ;-)