From: Axel Kohlmeyer (akohlmey_at_cmm.chem.upenn.edu)
Date: Thu Jun 07 2007 - 17:46:50 CDT

On Thu, 7 Jun 2007, lily jin wrote:

LJ> case 1:

LJ> I was writting a script. Because of some bugs it ran but only
LJ> partly. So some file opened was not closed. When I tried to delete
LJ> the file from the folder, I was told it was used.

let me guess: are you running on windows?
if this kind of behavior happens a lot, you could install
a special error handler, that records the open file pointers,
and then closes them on error. but i would actually try to
see this positively, and try to check more carefully whether
are script can work at all. alternatively, you can also write/debug
scripts by running them with 'vmd -dispdev text -e some_script.tcl'
or alike, where just do everything on the script level.
sure it is painful, when things are not convenient, but
by actively trying to avoid 'being inconvenienced' you can
actually become more proficient in writing scripts.
at least, this is my experience.

LJ> case 2:
LJ> when I use 'lappend lista $h ' in my script, I want to be sure that lista is empty when I start to run the program. I can use 'set lista {}' . But when I have a lot of commands like this in the script, I wish to have a clean memory with one command.
LJ> I always want to have a clean memory before I ran a program.
LJ> When this happend, especially case 1, I had to close VMD and start it again.
LJ> 'clear' is a command in Matlab which simply cleans the memory.

LJ> TCL has a command 'memory' which seems similar, however, it is not
LJ> working in VMD1.8.5. I don't know if I made a mistake.

this memory command is not default (see the manpage).
it is mostly needed for debugging the TCL port to a given platform.

as robert already pointed out, it is impossible to tell, which
variable/function/list/array is created by the vmd startup scripts
and which are created by you. this is a strength and deficiency
of TCL at the same time. unlike matlab, the startup of VMD is usually
very fast, so if you start working on a new problem, it should
not make much of a difference just to start a new copy of
VMD and exit the other one instead. the second copy of VMD usually
starts much, much faster than the first.

but then again, i'm working on a linux machine with quite
a bit of memory, which may make it much easier for me.

cheers,
   axel.

LJ>
LJ> Thank you for helping!
LJ>
LJ>
LJ>
LJ> Lily
LJ>
LJ>
LJ>
LJ> ----- Original Message ----
LJ> From: Axel Kohlmeyer <akohlmey_at_cmm.chem.upenn.edu>
LJ> To: lily jin <lily1907_at_yahoo.com>
LJ> Cc: VMD-L <vmd-l_at_ks.uiuc.edu>
LJ> Sent: Wednesday, June 6, 2007 2:35:17 PM
LJ> Subject: Re: vmd-l: release memory in TCL
LJ>
LJ>
LJ> On Wed, 6 Jun 2007, lily jin wrote:
LJ>
LJ> LJ> While I run a program, all the data are saved in the memory. How can
LJ> LJ> I remove them to clear the system memory, like what 'clear' does in
LJ> LJ> MATLAB? Thank you!
LJ>
LJ> there is not a single command in tcl, if i remember correctly.
LJ> but you can unset variables and arrays. they are also
LJ> cleaned up when used locally in a subroutine.
LJ>
LJ> the most memory loss in VMD is usually due to trajectory
LJ> data (you can delete molecules to free that) and from
LJ> creating selections without deleting them.
LJ>
LJ> other than that, it is easier to exit VMD and start over.
LJ>
LJ> do you have a specific problem or can you describe a
LJ> scenario where something akin to 'clear' would be
LJ> desirable?
LJ>
LJ> cheers,
LJ> axel.
LJ>
LJ> LJ>
LJ> LJ> Lily
LJ> LJ>
LJ> LJ>
LJ> LJ>
LJ> LJ> ____________________________________________________________________________________
LJ> LJ> Be a better Globetrotter. Get better travel answers from someone who knows. Yahoo! Answers - Check it out.
LJ> LJ> http://answers.yahoo.com/dir/?link=list&sid=396545469
LJ>
LJ>

-- 
=======================================================================
Axel Kohlmeyer   akohlmey_at_cmm.chem.upenn.edu   http://www.cmm.upenn.edu
   Center for Molecular Modeling   --   University of Pennsylvania
Department of Chemistry, 231 S.34th Street, Philadelphia, PA 19104-6323
tel: 1-215-898-1582,  fax: 1-215-573-6233,  office-tel: 1-215-898-5425
=======================================================================
If you make something idiot-proof, the universe creates a better idiot.