I was just working on this problem yesterday! :-)
Try something like the following code. Every node has to be deallocated
individually, otherwise it just sits there and takes up memory.
If you deallocate the head and tail nodes alone, you lose access to
the rest of the list but you haven't freed the memory that it's
taking up.
!***************************************************
SUBROUTINE DELETE_LIST(HEAD)
!***************************************************
IMPLICIT NONE
TYPE LLIST_TYPE
INTEGER :: INDX
TYPE(LLIST_TYPE), POINTER :: NEXT
END TYPE LLIST_TYPE
TYPE(LLIST_TYPE), POINTER :: HEAD,CURRENT,TMP
if (.not.associated(head)) return
current => head
do while (associated(current))
tmp => current%next
write(*,*) 'removing node = ',current%indx
deallocate(current)
current => tmp
end do
deallocate(head)
RETURN
END SUBROUTINE DELETE_LIST
--
-------------------------------------------------------------------------
Catherine Moroney phone : (818) 393-3392
Jet Propulsion Laboratory fax : (818) 393-4802
MailStop 169-315 email : [log in to unmask]
4800 Oak Grove Drive
Pasadena, CA 91109-8099
Junchao Xia wrote:
>
> Hi everyone,
> I am a new user of Fortran 90.
> I have a program which produces the int single-linked list very often.
> And I found the memory is getting biger and run out of it at last.
> I am sure that I deallocated the int node when I removed it. But I only
> nullify the head and the tail of the int list when I don't need the int
> list. Do the int nodes still own memory after I nullify the head and the
> tail? If do, how can I release the memory of an int list? Deallocate
> the int list or deallocate the int node one by one?
>
> Thanks.
>
> Junchao Xia
> Physics Department, Clark University
> Worcester, MA 01610, USA
> or
> #6 Shirley Street, Apartment #1,
> Worcester, MA 01610, USA
> tele: (508)793-7727(office),(508)767-0395(home)
> (508)793-7150(lab)
> Email: [log in to unmask],
> [log in to unmask],
> [log in to unmask]
> URL: http://physics.clarku.edu/~jcxia/
> _______________________________________
|