memory(n)
π NAME π
okay so bestie, welcome to memory β the Tcl command that lets you control Tcl's memory debugging capabilities. that's it, that's the whole vibe. it's the little backstage pass to the memory subsystem and honestly she's iconic for it.
this page lives in the Tcl Built-In Commands section of the manual (that's the (n) after her name, iykyk). π«Ά
β¨ SYNOPSIS β¨
memory option ?arg arg ...?
π§ DESCRIPTION π§
the memory command hands the Tcl developer the keys to Tcl's memory debugging capabilities. it's got a whole bunch of suboptions, all listed down below, and they are, no exaggeration, giving main character energy. π
real talk though: this command is only available when Tcl has been compiled with memory debugging enabled (that meansTCL_MEM_DEBUGis defined at compile time), and afterTcl_InitMemoryhas been called. no compile flag, no command. periodt.
πΈ the suboptions πΈ
memory activefile β writes a list of all currently allocated memory into the file you name. the whole inventory. every byte, accounted for.memory break_on_malloccount β after count allocations have been performed,Tcl_Allocoutputs a message to this effect and says it's now attempting to enter the C debugger. then Tcl issues aSIGINTsignal against itself. so if you're running Tcl under a C debugger, it should pop you right into the debugger command mode. dramatic? yes. useful? also yes. πmemory infoβ returns a report containing:- the total allocations and frees since Tcl began
- the current packets allocated (that's the current number of calls to
Tcl_Allocnot met by a corresponding call toTcl_Free) - the current bytes allocated
- the maximum number of packets and bytes allocated
she's a full report card. π
memory init[on|off]β turns the preinitialization of all allocated memory with bogus bytes on or off. super useful for detecting the use of uninitialized values. (bogus bytes are basically little tripwires, love that for us. β¨)memory objsfile β causes a list of all allocatedTcl_Objvalues to be written to the specified file immediately, together with where they were allocated. useful for checking for leaks of values. π΅οΈββοΈmemory onexitfile β causes a list of all allocated memory to be written to the specified file during the finalization of Tcl's memory subsystem. useful for checking that memory is properly cleaned up during process exit. she tidies up before she leaves, as she should. πmemory tagstring β every packet of memory allocated byTcl_Alloccan have a string-valued tag associated with it. in the lists of allocated memory generated bymemory activeandmemory onexit, the tag for each packet is printed along with other information about the packet. thememory tagcommand sets the tag value for subsequent calls toTcl_Allocto be string. it's giving name tags at a party, honestly. π·οΈmemory trace[on|off]β turns memory tracing on or off. when memory tracing is on, every call toTcl_Alloccauses a line of trace information to be written tostderr, consisting of the wordTcl_Alloc, followed by the address returned, the amount of memory allocated, and the C filename and line number of the code performing the allocation. for example:
Tcl_Alloc 40e478 98 tclProc.c 1406
calls to Tcl_Free are traced in the same manner. π
memory trace_on_at_malloccount β enable memory tracing after countTcl_Allocs have been performed. for example, if you entermemory trace_on_at_malloc 100, after the 100th call toTcl_Alloc, memory trace information will begin being displayed for all allocations and frees. since there can be a lot of memory activity before a problem occurs, judicious use of this option can reduce the slowdown caused by tracing (and the amount of trace information produced), if you can identify a number of allocations that occur before the problem sets in. the current number of memory allocations that have occurred since Tcl started is printed on a guard zone failure. π₯memory validate[on|off]β turns memory validation on or off. when memory validation is enabled, on every call toTcl_AllocorTcl_Free, the guard zones are checked for every piece of memory currently in existence that was allocated byTcl_Alloc. this has a large performance impact and should only be used when overwrite problems are strongly suspected. π¬ the advantage of enabling memory validation is that a guard zone overwrite can be detected on the first call toTcl_AllocorTcl_Freeafter the overwrite occurred, rather than when the specific memory with the overwritten guard zone(s) is freed β which may occur long after the overwrite occurred. so yeah, slow but psychic. pick your fighter. π
π SEE ALSO π
Tcl_AllocTcl_FreeTcl_ValidateAllMemoryTcl_DumpActiveMemoryTCL_MEM_DEBUG
π KEYWORDS π
memory, debug
okay bestie that's the whole page, you ate it, go debug something and slay. π
this was the memory(n) page from the Tcl Built-In Commands manual β Tcl 8.1, dated... well, whenever 8.1 said so. mwah, no notes. π«Άβ¨π
π¦ where this page comes from
- alpine 3.23: tcl9-doc 9.0.3-r0 Β· TCL
- alpine 3.24: tcl9-doc 9.0.3-r2 Β· TCL
- fedora 43: tcl-doc 1:9.0.2-1.fc43 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- fedora 44: tcl-doc 1:9.0.2-1.fc44 Β· TCL AND GPL-3.0-or-later WITH Bison-exception-2.2 AND BSD-3-Clause
- nixos 26.05: tcl 9.0.3
- Copyright (c) 1992-1999 Karl Lehenbauer & Mark Diekhans
- Copyright (c) 2000 Scriptics Corporation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms