I would like to add that it may be better, depending on the specifics of
the application, to keep a "deleted list" with its own head node. Thus,
deleting a node from the primary list will be a matter of inserting it
into the list of deleted items (very fast). You can then run the
node-by-node deallocation routine at your own convenience, for example
when you have more than a certain number of deleted nodes.
Alvaro Fernandez
Athena Technology Consultants
-----Original Message-----
From: Fortran 90 List [mailto:[log in to unmask]] On Behalf
Of Craig Dedo
Sent: Thursday, February 06, 2003 11:08 AM
To: [log in to unmask]
Subject: Re: deallocate list
Dear Mr. Xia:
You have hit upon the infamous memory leak. Deallocating only the
head
and tail nodes will not automatically deallocate any of the other nodes
in
the list. Instead, they still remain allocated, but unavailable, and
still
consume memory.
Yes, you will need to deallocate all of the nodes one by one. You
should
probably write a procedure to do deallocate all of the nodes at the same
time, so that you only have to call the procedure when you need to
deallocate
the entire list.
The only way that you would get automatic deallocation of an entire
linked list would be if the compiler you are using supports automatic
garbage
collection. Such a feature is beyond the scope of the Fortran standard.
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/
> _______________________________________
--
----------
Sincerely,
Craig T. Dedo
17130 W. Burleigh Place Internet: [log in to unmask]
Brookfield, WI 53005-2759 Voice Phone: (262) 783-5869
USA Fax Phone: (262) 783-5928
"They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety." -- Benjamin Franklin
(1759)
|