ADC Home > Reference Library > Technical Q&As > Legacy Documents > Mac OS 9 & Earlier >

MemError

Q: When I am debugging my application MemError always returns noErr. What's wrong with MemError?

A: Nothing, if you are debugging your application with a high level debugger. High level debuggers often call Memory Manager routines while stepping through your code. When a Memory Manager routine is called, it sets MemError and in this case, the debugger's memory request was successful (it returned noErr) and cleared your application's MemError result.

The solution to this problem is often just to not step over Memory Manager calls and the call to MemError. If you put a break point just after the MemError call, you usually get the correct error - the one your application would see if it wasn't running in the debugger.

The other option is to use a low level debugger such as MacsBug to debug your memory allocation problems.

As a general rule your application should check the value of the handle or pointer returned by NewHandle, NewPtr, etc: and if it is nil, you should call MemError for an error number. Just calling MemError without checking the value of the handle/pointer is not a good idea.

[Sep 12 1997]


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.