Magne Rudshaug wrote:
>
> Hi everyone!
>
> I have a question concerning deallocation of an abstract data types (ADT's)
> containing pointer components. Let us say I have a situation as follows:
>
> TYPE :: ExType
> CHARACTER(LEN=10) :: Name
> REAL, POINTER :: Data(:)
> END TYPE ExType
>
> TYPE(ExType), POINTER :: InsType
>
> ALLOCATE( InsType )
>
> ALLOCATE( InsType%Data(100) )
>
> Some code ....
>
> DEALLOCATE( InsType )
>
> My question is as follows: Will the DEALLOCATE statement above also
> automatically deallocate the pointer component Data in a way not leading to
> memory leaks? Or do I have to take care of this explicitly myself by
> issuing the following sequence of commands instad:
>
> DEALLOCATE( InsType%Data )
>
> DEALLOCATE( InsType )
>
> Thanks in advance for a reply!
You need to do the double deallocation. The compiler would need to
arrange for the program to keep a record of the fact that the target was
allocated directly and that no other pointers are pointing to it. I
doubt if many would think this worthwhile. What you need are allocatable
components, coming in Fortran 2000.
John Reid.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|