Technical Q&As


ME06 - MemError (12-September-97)


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.


-- Mark Cookson
Worldwide Developer Technical Support

Technical Q&As
Previous Question | Contents | Next Question

To contact us, please use the Contact Us page.