| 1 |
'\" |
| 2 |
'\" Copyright (c) 1992-1999 Karl Lehenbauer & Mark Diekhans |
| 3 |
'\" Copyright (c) 2000 Scriptics Corporation. |
| 4 |
'\" All rights reserved. |
| 5 |
'\" |
| 6 |
.TH memory n 8.1 Tcl "Tcl Built-In Commands" |
| 7 |
.so man.macros |
| 8 |
.BS |
| 9 |
.SH NAME |
| 10 |
memory \- Control Tcl memory debugging capabilities |
| 11 |
.SH SYNOPSIS |
| 12 |
\fBmemory \fIoption \fR?\fIarg arg ...\fR? |
| 13 |
.BE |
| 14 |
.SH DESCRIPTION |
| 15 |
.PP |
| 16 |
The \fBmemory\fR command gives the Tcl developer control of Tcl's memory |
| 17 |
debugging capabilities. The memory command has several suboptions, which are |
| 18 |
described below. It is only available when Tcl has been compiled with |
| 19 |
memory debugging enabled (when \fBTCL_MEM_DEBUG\fR is defined at |
| 20 |
compile time), and after \fBTcl_InitMemory\fR has been called. |
| 21 |
.TP |
| 22 |
\fBmemory active\fR \fIfile\fR |
| 23 |
. |
| 24 |
Write a list of all currently allocated memory to the specified \fIfile\fR. |
| 25 |
.TP |
| 26 |
\fBmemory break_on_malloc\fR \fIcount\fR |
| 27 |
. |
| 28 |
After the \fIcount\fR allocations have been performed, \fBckalloc\fR |
| 29 |
outputs a message to this effect and that it is now attempting to enter |
| 30 |
the C debugger. Tcl will then issue a \fISIGINT\fR signal against itself. |
| 31 |
If you are running Tcl under a C debugger, it should then enter the debugger |
| 32 |
command mode. |
| 33 |
.TP |
| 34 |
\fBmemory info\fR |
| 35 |
. |
| 36 |
Returns a report containing the total allocations and frees since |
| 37 |
Tcl began, the current packets allocated (the current |
| 38 |
number of calls to \fBckalloc\fR not met by a corresponding call |
| 39 |
to \fBckfree\fR), the current bytes allocated, and the maximum number |
| 40 |
of packets and bytes allocated. |
| 41 |
.TP |
| 42 |
\fBmemory init \fR[\fBon\fR|\fBoff\fR] |
| 43 |
. |
| 44 |
Turn on or off the preinitialization of all allocated memory |
| 45 |
with bogus bytes. Useful for detecting the use of uninitialized |
| 46 |
values. |
| 47 |
.TP |
| 48 |
\fBmemory objs \fIfile\fR |
| 49 |
. |
| 50 |
Causes a list of all allocated Tcl_Obj values to be written to the specified |
| 51 |
\fIfile\fR immediately, together with where they were allocated. Useful for |
| 52 |
checking for leaks of values. |
| 53 |
.TP |
| 54 |
\fBmemory onexit\fR \fIfile\fR |
| 55 |
. |
| 56 |
Causes a list of all allocated memory to be written to the specified \fIfile\fR |
| 57 |
during the finalization of Tcl's memory subsystem. Useful for checking |
| 58 |
that memory is properly cleaned up during process exit. |
| 59 |
.TP |
| 60 |
\fBmemory tag\fR \fIstring\fR |
| 61 |
. |
| 62 |
Each packet of memory allocated by \fBckalloc\fR can have associated |
| 63 |
with it a string-valued tag. In the lists of allocated memory generated |
| 64 |
by \fBmemory active\fR and \fBmemory onexit\fR, the tag for each packet |
| 65 |
is printed along with other information about the packet. The |
| 66 |
\fBmemory tag\fR command sets the tag value for subsequent calls |
| 67 |
to \fBckalloc\fR to be \fIstring\fR. |
| 68 |
.TP |
| 69 |
\fBmemory trace \fR[\fBon\fR|\fBoff\fR] |
| 70 |
. |
| 71 |
Turns memory tracing on or off. When memory tracing is on, every call |
| 72 |
to \fBckalloc\fR causes a line of trace information to be written to |
| 73 |
\fIstderr\fR, consisting of the word \fIckalloc\fR, followed by the |
| 74 |
address returned, the amount of memory allocated, and the C filename |
| 75 |
and line number of the code performing the allocation. For example: |
| 76 |
.RS |
| 77 |
.PP |
| 78 |
.CS |
| 79 |
ckalloc 40e478 98 tclProc.c 1406 |
| 80 |
.CE |
| 81 |
.PP |
| 82 |
Calls to \fBckfree\fR are traced in the same manner. |
| 83 |
.RE |
| 84 |
.TP |
| 85 |
\fBmemory trace_on_at_malloc\fR \fIcount\fR |
| 86 |
. |
| 87 |
Enable memory tracing after \fIcount\fR \fBckalloc\fRs have been performed. |
| 88 |
For example, if you enter \fBmemory trace_on_at_malloc 100\fR, |
| 89 |
after the 100th call to \fBckalloc\fR, memory trace information will begin |
| 90 |
being displayed for all allocations and frees. Since there can be a lot |
| 91 |
of memory activity before a problem occurs, judicious use of this option |
| 92 |
can reduce the slowdown caused by tracing (and the amount of trace information |
| 93 |
produced), if you can identify a number of allocations that occur before |
| 94 |
the problem sets in. The current number of memory allocations that have |
| 95 |
occurred since Tcl started is printed on a guard zone failure. |
| 96 |
.TP |
| 97 |
\fBmemory validate \fR[\fBon\fR|\fBoff\fR] |
| 98 |
. |
| 99 |
Turns memory validation on or off. When memory validation is enabled, |
| 100 |
on every call to \fBckalloc\fR or \fBckfree\fR, the guard zones are |
| 101 |
checked for every piece of memory currently in existence that was |
| 102 |
allocated by \fBckalloc\fR. This has a large performance impact and |
| 103 |
should only be used when overwrite problems are strongly suspected. |
| 104 |
The advantage of enabling memory validation is that a guard zone |
| 105 |
overwrite can be detected on the first call to \fBckalloc\fR or |
| 106 |
\fBckfree\fR after the overwrite occurred, rather than when the |
| 107 |
specific memory with the overwritten guard zone(s) is freed, which may |
| 108 |
occur long after the overwrite occurred. |
| 109 |
.SH "SEE ALSO" |
| 110 |
ckalloc, ckfree, Tcl_ValidateAllMemory, Tcl_DumpActiveMemory, TCL_MEM_DEBUG |
| 111 |
.SH KEYWORDS |
| 112 |
memory, debug |
| 113 |
'\"Local Variables: |
| 114 |
'\"mode: nroff |
| 115 |
'\"End: |