David Leal wrote:
>
> Dear Members:
>
> About my question I have received the following answered
>
> > subroutine foo()
> > integer,pointer :: x
> >
> > allocate(x)
> > .
> > .
> > .
> > nullify(x)
>
> >This will disassociate x but I think, the memory that wass allocated
> >is still occupied but inaccessable.
>
> Is that true?
In general, yes. I believe the DEC fortran compiler at least tries to
clear up memory that is allocated in a subroutine after you leave the
subroutine (at least if it was defined as allocatable), but don't rely
on it.
>
> So in order to get a really free memory is better to do deallocation in
> this case instead of nullify.
Yes.
>
> Is there any program for checking the garbage collector ?
> I am very careful in my program in this sense and for each allocate
> statement I have the corresponding deallocate statement before the
> return statement and in the same way for the pointer association. For
> each association (=>) I have the corresponding nullify statement before
> the return statement. My program is very large so it is possible that I
> have forgotten some nullify or deallocation statement somewhere. I have
> problem with allocation memory with a medium size problem. I am using an
> iterative process and I am afraid that from one iteration to the next
> the garbage collector increase. Is there any way to check this
> situation.
>
Fortran does not have garbage collection. You do it yourself, which is
more efficient I think. Of course you have to be more careful.
If you have allocation/deallocation in subroutines it is much safer to
use automatic arrays.
subroutine my (n)
integer, intent(in) :: n
real(..) :: A(n)
...
end subroutine my
Problem is that, if there is not enough memory available, this will just
bomb. So be careful to set all the system limits high enough (see limit
or ulimit).
But now you don't have to do any allocation/de-allocation, it is
generally faster and you have no memory leaks.
Adriaan
--
--------------------------------------+-------------------------------
Dr Adriaan Joubert | Phone: +357-2-750 652
APL Financial Services (Overseas) Ltd| Fax: +357-2-750 654
3 D. Vikella St | e-mail: [log in to unmask]
1061 Nicosia, CYPRUS |
--------------------------------------+-------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|