memory(3tcl)
π NAME π
memory β okay bestie, this is the command that gives you control of Tcl's memory debugging capabilities. it's giving detective energy πβ¨ (and it's from the memory(3tcl) page in the Tcl Built-In Commands manual, just so you know where we're at π
)
β¨ SYNOPSIS β¨
memory option ?arg arg ...?
π§ DESCRIPTION π§
okay so. The memory command gives the Tcl developer control of Tcl's memory debugging capabilities. That's literally its whole job. It has several suboptions, and we are going through every single one, no skipping, no "you get the gist" 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. it's giving exclusive. π
πΈ memory active file
Writes a list of all currently allocated memory to the specified file. very "who is still here and why" of it. π¦
π₯ memory break_on_malloc count
After the count allocations have been performed, Tcl_Alloc outputs a message to this effect and that it is now attempting to enter the C debugger. Tcl will then issue a SIGINT signal against itself. If you are running Tcl under a C debugger, it should then enter the debugger command mode. it's literally self-sabotage as a feature, and honestly? iconic. π
π memory info
Returns a report containing the total allocations and frees since Tcl began, the current packets allocated (the current number of calls to Tcl_Alloc not met by a corresponding call to Tcl_Free), the current bytes allocated, and the maximum number of packets and bytes allocated. it's the receipts. π
π memory init [on|off]
Turns on or off the preinitialization of all allocated memory with bogus bytes. Useful for detecting the use of uninitialized values. (bogus bytes, bestie. bogus bytes. obsessed with that phrasing fr fr.) π
π memory objs file
Causes a list of all allocated Tcl_Obj values to be written to the specified file immediately, together with where they were allocated. Useful for checking for leaks of values. leak check but make it forensic π₯
πͺ memory onexit file
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. it's the "did you actually clean your room before leaving" check. π
π·οΈ memory tag string
Each packet of memory allocated by Tcl_Alloc can have associated with it a string-valued tag. In the lists of allocated memory generated by memory active and memory onexit, the tag for each packet is printed along with other information about the packet. The memory tag command sets the tag value for subsequent calls to Tcl_Alloc to be string. it's name-tagging your mallocs, so cute, so useful. β
π memory trace [on|off]
Turns memory tracing on or off. When memory tracing is on, every call to Tcl_Alloc causes a line of trace information to be written to stderr, consisting of the word Tcl_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. no cap, every single one. π«Ά
β±οΈ memory trace_on_at_malloc count
Enable memory tracing after count Tcl_Allocs have been performed. For example, if you enter memory trace_on_at_malloc 100, after the 100th call to Tcl_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. strategic. we love a delayed reaction that's actually a plan. π§
π‘οΈ memory validate [on|off]
Turns memory validation on or off. When memory validation is enabled, on every call to Tcl_Alloc or Tcl_Free, the guard zones are checked for every piece of memory currently in existence that was allocated by Tcl_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 to Tcl_Alloc or Tcl_Free after 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.
π¨ yes bestie, large performance impact β do not just leave this on for the aesthetic. turn it on when overwrite problems are strongly suspected, catch the crime at the scene, then turn it back off. π
π SEE ALSO π
Tcl_AllocTcl_FreeTcl_ValidateAllMemoryTcl_DumpActiveMemoryTCL_MEM_DEBUG
π KEYWORDS π
memory, debug
and that's the whole page, bestie β every flag, every suboption, every guard zone, all of it. this was Tcl 8.1's memory(3tcl) page, so shoutout to that version and its date, mwah πβ¨ bye!! ππ¦
π¦ where this page comes from
- debian trixie: tcl9.0-doc 9.0.1+dfsg-2
- ubuntu questing: tcl9.0-doc 9.0.2+dfsg-1
- ubuntu resolute: tcl9.0-doc 9.0.3+dfsg-1
- ubuntu stonking: tcl9.0-doc 9.0.4+dfsg-1
- 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