Changes between Initial Version and Version 1 of MemoryLeaks


Ignore:
Timestamp:
08/14/08 21:41:47 (6 years ago)
Author:
wws
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • MemoryLeaks

    v1 v1  
     1{{{ 
     2#!html 
     3<p> 
     4<font color="blue"><b> 
     5The information below describes a feature currently available only in the <a href="http://trac.clozure.com/openmcl/browser/branches/working-0711">working-0711</a> branch in subversion</b></font> 
     6}}} 
     7CCL has a handful of functions that can help find memory leaks. 
     8 
     9=== Finding Lisp Heap Leaks === 
     10 
     11You can usually tell that you have a lisp heap leak, by comparing the output of room before and after running some suspect code: 
     12 
     13{{{ 
     14(progn 
     15  (ccl:gc) 
     16  (ccl:gc) 
     17  (room)) 
     18}}} 
     19 
     20The two calls to `CCL:GC` are to make sure that finalization and weak objects are collected. 
     21 
     22Once you know you have a leak, comparing two outputs of `(CCL:HEAP-UTILIZATION)` can sometimes narrow down the possibilities. 
     23 
     24`(CCL::ALL-OBJECTS-OF-TYPE 'type)` returns a list of the objects counted in one line of the `(CCL:HEAP-UTILIZATION)` output. These tend to be long, so you usually want to avoid printing them, e.g. `(DEFPARAMETER *STRINGS* (CCL::ALL-OBJECTS-OF-TYPE 'SIMPLE-BASE-STRING))`. 
     25 
     26You can use `CCL::FAST-SET-DIFFERENCE` to compute the difference between two results from `CCL::ALL-OBJECTS-OF-TYPE`. It's just like the Common Lisp `SET-DIFFERENCE` function, except it uses a hash table for better speed versus more space. 
     27 
     28`(CCL::FIND-REFERENCES OBJECT)` returns a list of all objects that reference the argument. 
     29 
     30`(TRANSITIVE-REFERENCERS OBJECT-OR-LIST &OPTIONAL AS-OBJECT)` returns a hash table whose keys are objects that transitively reference `OBJECT-OR-LIST` or, if it's a list and `AS-OBJECT` is nil, any of its elements. 
     31 
     32`(CCL::PRINT-REFERENCERS HASH &KEY PREDICATE PAUSE-PERIOD PRINT-CIRCLE PRINT-LENGTH PRINT-LEVEL)` prints the hash table returned by `TRANSITIVE-REFERENCERS`. The key parameters control filtering and printing variables. 
     33 
     34 
     35=== Finding C heap leaks === 
     36 
     37Sometimes memory leaks are due to `malloc()` calls in the C memory manager, not the lisp heap. 
     38 
     39`(CCL::MALLINFO)` returns the total number of malloc'd bytes. Like room, its output takes a few garbage collectes to stabilize. 
     40 
     41Linux has a facility called "mtrace" that lets you save to a file all calls to malloc and free. Then you can parse that file to find memory that was allocated, but not deallocated, along with where in which library the allocation was done. Not as useful as a stack dump for each one, but still often useful. 
     42 
     43`(CCL::START-MTRACE FILENAME)` begins logging, storing the log in FILENAME. 
     44 
     45`(CCL::STOP-MTRACE)` stops logging 
     46 
     47`(CCL::PARSE-MTRACE-LOG FILENAME)` parses the mtrace output, and returns a list of three-element lists, of the form: (Where Size Pointer). Where is the location of unbalanced call to malloc. Size is the size of the allocated pointer. Pointer is the location of the pointer itself. Both `START-MTRACE` and `STOP-MTRACE` call `CCL:GC` once, but you may want to call it and look at the `(CCL::MALLINFO)` output until the garbage collector has recovered all it can.