typedstream IBObjectData Object CustomObject WindowManager Responder ScrollView ClipView ciifffcfffs [6855c]{\rtf0\ansi{\fonttbl\f1\fnil Times-Roman;\f0\fswiss Helvetica;} \margl40 \margr40 {\colortbl;\red0\green0\blue0;} \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f1\b0\i0\ul0\fs36\fc0\cf0 \ Introduction \fs32 \ \fs28 \ \b MallocDebug \b0 is a utility for measuring the dynamic memory usage of applications and for finding memory leaks. You can use \pard\tx1040\tx2100\tx3160\tx4220\tx5280\tx6320\tx7380\tx8440\tx9500\tx10560\b\fc1\cf1 MallocDebug \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fc0\cf0 to measure all allocated memory in an application, or to measure the memory allocated since a given point in time. \pard\tx1040\tx2100\tx3160\tx4220\tx5280\tx6320\tx7380\tx8440\tx9500\tx10560\b\fc1\cf1 MallocDebug \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fc0\cf0 also contains a conservative garbage detector that can be used to detect memory leaks.\ \fs36 Preparing your Application\ \fs28 \ To use \pard\tx1040\tx2100\tx3160\tx4220\tx5280\tx6320\tx7380\tx8440\tx9500\tx10560\b\fc1\cf1 MallocDebug \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fc0\cf0 , you must link your application with a library containing a special version of \b malloc \b0 that will communicate with \pard\tx1040\tx2100\tx3160\tx4220\tx5280\tx6320\tx7380\tx8440\tx9500\tx10560\b\fc1\cf1 MallocDebug \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fc0\cf0 . To do this link with the library \b /usr/lib/libMallocDebug.a \b0 using the linker option \b -lMallocDebug \b0 . The \b -lMall \b0 option must be placed \i before \i0 the \b -lsys_s \b0 option, to ensure that \b malloc \b0 is overridden properly. If your application is built with the \b Interface Builder \b0 , you can simply add \b /usr/lib/MallocDebug.a \b0 to the Other libs section of the Project Inspector.\ \fs36 Using \pard\tx1040\tx2100\tx3160\tx4220\tx5280\tx6320\tx7380\tx8440\tx9500\tx10560\b\fc1\cf1 MallocDebug \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fc0\cf0 \ \fs28 \ To use \pard\tx1040\tx2100\tx3160\tx4220\tx5280\tx6320\tx7380\tx8440\tx9500\tx10560\b\fc1\cf1 MallocDebug \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fc0\cf0 , you must first select an application to monitor. The \i Open \i0 menu item in the \i Application \i0 menu brings up the \i Select \i0 panel. Only applications which you own and which have been configured for use with \pard\tx1040\tx2100\tx3160\tx4220\tx5280\tx6320\tx7380\tx8440\tx9500\tx10560\b\fc1\cf1 MallocDebug \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fc0\cf0 will appear in the panel. Select an application by double-clicking its icon, and \pard\tx1040\tx2100\tx3160\tx4220\tx5280\tx6320\tx7380\tx8440\tx9500\tx10560\b\fc1\cf1 MallocDebug \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fc0\cf0 's application window will appear.\ When the \i All \i0 button is pressed, \pard\tx1040\tx2100\tx3160\tx4220\tx5280\tx6320\tx7380\tx8440\tx9500\tx10560\b\fc1\cf1 MallocDebug \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fc0\cf0 displays a list of all currently allocated nodes in your application. These nodes have been allocated by one of the standard C allocation functions ( \b malloc \b0 , \b realloc \b0 , \b calloc \b0 , or \b valloc \b0 ) or one of NeXT's zone allocation functions ( \pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\b\fc1\cf1 NXZoneMalloc \b0 , \b NXZoneRealloc \b0 , \b NXZoneCalloc \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fc0\cf0 ). Each row displays the zone in which the node was allocated, the address and size of the node and the procedure that allocated the node. The nodes can be sorted by allocator, by order of al tion, or by zone.\ \fs36 Damaged Nodes\ \fs28 \ \pard\tx1040\tx2100\tx3160\tx4220\tx5280\tx6320\tx7380\tx8440\tx9500\tx10560\b\fc1\cf1 MallocDebug \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fc0\cf0 also detects nodes that have been written to incorrectly. If your application has written past the end of a node, a right arrow (`>') appears by the node. Similarly, if your application has written before the start of a node, a left arrow (`<') appears by the node. Many of these errors are the result of using the result of \b strlen(s) \b0 as the argument to \b malloc \b0 for a string instead of \b strlen (s) + 1 \b0 . Damaged nodes are listed first in all sorting modes.\ \fs36 Finding Memory Leaks\ \fs28 \ To detect memory leaks, \pard\tx1040\tx2100\tx3160\tx4220\tx5280\tx6320\tx7380\tx8440\tx9500\tx10560\b\fc1\cf1 MallocDebug \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fc0\cf0 contains a \i conservative garbage detector \i0 .\ When the \i Leaks \i0 button is pressed, \pard\tx1040\tx2100\tx3160\tx4220\tx5280\tx6320\tx7380\tx8440\tx9500\tx10560\b\fc1\cf1 MallocDebug \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fc0\cf0 searches through your program's memory for pointers to each node. Any node that cannot be referenced is displayed as a memory leak. Since the garbage detector cannot know which words in memory are pointers, it is possible that an integer has the same value as a pointer to a given node. In this case that node doesn't show up as a leak, even though it really is. This is why the garbage detector is called \i conservative \i0 . In practice, this problem is very rare.\ The second caveat is that the garbage detector only searches for references to the \i beginning \i0 of each node. If your program doesn't retain a pointer to the start of a node, but instead retains a pointer into the middle of it, that node will show up as a leak even though it really isn't one.\ \fs36 Measuring Memory Usage\ \fs28 \ \pard\tx1040\tx2100\tx3160\tx4220\tx5280\tx6320\tx7380\tx8440\tx9500\tx10560\b\fc1\cf1 MallocDebug \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fc0\cf0 can show you the memory usage of a given portion of your program. To begin measur press the \i Mark \i0 button. After exercising a portion of your program, press the \i New \i0 button to see the nodes allocated since the mark. Note that \pard\tx1040\tx2100\tx3160\tx4220\tx5280\tx6320\tx7380\tx8440\tx9500\tx10560\b\fc1\cf1 MallocDebug \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\b0\fc0\cf0 always shows you the nodes that are still \i currently \i0 allocated, so you will see only those nodes allocated since the mark that haven't been freed.\ NXCursor NXImage NXibeam Scroller Control _doScroller: @@@ffs WindowTemplate iiii***@s@ Panel File's Owner ScrollingText HelpPanel IBOutletConnector IBConnector window