DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
No More Memory Leaks - fs(C++)

Freestore events

fs notifies the programmer when certain freestore events are about to take place. The most important of these events is object deletion.

When debugging freestore allocation bugs, programmers often need to determine where and when a certain freestore object is deleted. It is difficult to determine this information from reading the program, since objects can be deleted in time and space far removed from where they are newed. fs solves this problem by allowing the user to set a ``watchpoint'' on any object in the freestore. Calling the function fs_watch(5) in the current context sets a watchpoint on object #5. Now when (if ever) object #5 is about to be deleted, fs will first break program execution at the line containing the ``delete'' statement, and notify the programmer of the imminent deletion.

(In the actual implementation, fs does not itself break, since fs is implemented as part of the application code, not part of the debugger. Instead, fs ``requests'' a break by calling the empty function fs_break. In order for these requests to be fulfilled, the programmer must set an actual breakpoint on fs_break once at the start of debugging.

fs can also watch for the birth of objects. If object #5 does not yet exist, calling the function fs_watch(5) causes execution to break when object #5 is about to be newed. Either kind of watchpoint can be removed at any time by calling fs_unwatch(5).

The entire freestore can also be watched for arbitrary deletion or newing events. There are two functions to do this:

   fs_watchall_d() - break at the next delete
   fs_watchall_n() - break at the next new

These functions cause the program to break whenever any object is about to be deleted or newed. These global watches can be removed by calling fs_unwatchall_d() or fs_unwatchall_n(). These do not remove any watchpoints set on particular objects.


Next topic: The Marriage of fs and Debuggers
Previous topic: Looking at the freestore

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005