I wouldn't consider that a sufficient test.  John Muth wrote a great article
on a technique to detect memory leaks:

http://www.cdpubs.com/hhsys/archives/62/07muth.pdf

The idea is to intercept MemPtrNew and MemPtrFree.  Each time you're asked
to allocate new memory through MemPtrNew, you allocate slightly more bytes
than requested.  Then you pad a known pattern of bytes to the beginning and
end of the pointer you return (that only you know about), and store the
pointer you've returned in a linked list.  The caller never knows about
this.

On MemPtrFree, you find the pointer in your linked list, and check to make
sure your known pattern is still intact at the beginning and end of the
memory area, and remove the ptr from the linked list.  If the known pattern
has been altered, that indicates that someone wrote beyond the bounds of the
pointer (bad!).  Also if the app is terminated and there are still entries
in your linked list, that means someone failed to deallocate a pointer
altogether.

Though personally I would just use SysSetTrapAddress( sysMemPtrNewTrap,
MyMemPtrNew ) to put a wrapper on MemPtrNew, and similarly for MemPtrFree.
That way you don't have to go through and change all your code to call
CLMemPtrNew, as the article suggests.  Just be sure to reset the device when
you're done testing.  Quick and dirty.

As far as knowing WHERE the leak occurs, just put an ErrNonFatalDisplayIf()
in your MemPtrFree routine when you sense something bad has occured.  Then
debug into the code and see which pointer caused the problem, and you should
be able to take it from there.  If you need more proactive debugging, maybe
__FILE__ and __LINE__ are the right thing for you (see the article).

One of these days I'll get around to writing this up and passing it around
this list, unless someone else does it first.

-Jeff Ishaq
The Windward Group


-----Original Message-----
From: Michael S. Davis [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, November 02, 1999 11:46 AM
To: [EMAIL PROTECTED]
Subject: Test for Memory Leaks ?



Is there a simple test to determine if an app has a memory
leak?  Details?

I have done this test.  Check available memory with 'info'.
Run the app throughout the day.  Check 'info' again and
verify that the same amount of memory is available.  

Is this sufficient to confirm that there are no memory
leaks?

----------------------------------------------------
Shoot-to-Win

Protect the 2nd Amendment
----------------------------------------------------

Reply via email to