Re: [tkined] tcl memory allocation

Juergen Schoenwaelder (schoenw@ibr.cs.tu-bs.de)
Fri, 15 May 1998 12:42:33 +0200

>>>>> Christopher Akritides writes:

Christopher> I was wondering how tcl allocates and frees memory when
Christopher> you call a procedure within a procedure.

Depends on the Tcl version.

Christopher> Isn't the memory allocated to the subprocedure supposed
Christopher> to be freed when it returns?

Basically yes. Local variables go away once you return from a
procedure and if there are no further references to it. However, the
byte-compiler and the Tcl_Obj system can cause to keep memory
allocated. For example, the compiler will compile the body of a
procedure when it is called the first time and keep a copy of the
compiled byte code around in case the procedure is called again. This
means that the memory usage will increase whenever you call a "new"
procdure. Similar things can happen is you pass Tcl_Objs around.

Christopher> Does it matter what the subprocedure does if it does not
Christopher> increase the size of global variables?

See my comment above. Memory allocations and usage is less obvious
with the byte compiler than it was before. (Even under Tcl7.X, you
could "loose" memory because Tcl for example caches compiled regular
expressions. So if your procedure used a regular expression the first
time, some memory might be allocated to hold the compiled format of the
expression in cases it is used again.)
Juergen

Juergen Schoenwaelder schoenw@ibr.cs.tu-bs.de http://www.cs.tu-bs.de/~schoenw
Technical University Braunschweig, Dept. Operating Systems & Computer Networks
Bueltenweg 74/75, 38106 Braunschweig, Germany. (Tel. +49 531 / 391 3283)

--
!! This message is brought to you via the `tkined & scotty' mailing list.
!! Please do not reply to this message to unsubscribe. To subscribe or
!! unsubscribe, send a mail message to <tkined-request@ibr.cs.tu-bs.de>.
!! See http://wwwsnmp.cs.utwente.nl/~schoenw/scotty/ for more information.