Memory leaks in allocatable components
Paul Richard Thomas <paul.richard.thomas <at> gmail.com>
2008-06-02 12:50:24 GMT
Dear All,
As some of you might know, I have been claiming as an excuse for
inaction of all sorts that I am busy trying to sort out memory leaks
in allocatable components. Since this excuse is becoming so well
worn, I thought that I had better explain what I am up to!
To a good approximation, the problems are entirely associated with
structure components. There are memory leaks with forall and where
assignments. However, these are easily fixed as they were for
ordinary assignments.
Most usually, the problems are specific to nested constructors, each
with allocatable components, although that is not the whole story. I
have tried all sorts of kludges to get this right but, at the end of
the day, it is a fundamental problem with the functions called by
trans-expr.c(gfc_conv_structure) that is to blame:- namely, the gfc_se
structure is not passed to them so that the -pre and -post blocks are
not available. Not only does this put these functions outside of the
gfortran norms but it prevents the kind of clean-up that is required
here. Thus, I am working on this reform of the translation of
structure constructors to begin with and will return to allocatable
components right away afterwards. Once there is a post-block that is
accessible to the innermost parts, eg. gfc_trans_subcomponent_assign,
then we can de-allocate memory assigned to allocatable components,
following a final deep copy to the lhs of the assignment. This is
what is done everywhere else in gfortran.
Bear with me!
(Continue reading)