Q:I read somewhere that you don't have to call CloseOpenTransport if you're
writing an application. Is this true?
A:
Yes and no. The original OT programming documentation stated that calling
CloseOpenTransport was optional for applications. There is however a bug in OT
1.1 and earlier which will not properly clean up PPC native applications when
they terminate unless CloseOpenTransport is called.
Here are some rules of thumb:
- Non-application code must always call
CloseOpenTransport when it
terminates.
- It is best if 68K applications call
CloseOpenTransport , but they will be
cleaned up automatically if they don't.
- Make sure that PPC applications running under OT 1.1 or earlier call
CloseOpenTransport when terminating.
One way of ensuring that you comply with point 3 is to use a CFM terminate
procedure in your main application fragment, such as:
static Boolean gOTInited = false;
void CFMTerminate(void)
{
if (gOTInited) {
gOTInited = false;
(void) CloseOpenTransport();
}
}
void main(void)
{
OSStatus err;
err = InitOpenTransport();
gOTInited = (err == noErr);
// the rest of your application
if (gOTInited) {
(void) CloseOpenTransport();
gOTInited = false;
}
}
|
Note:
Calling CloseOpenTransport is always required for non-application
programs.
|
Note:
When the Mac OS provides an automatic clean up mechanism, it's
normally intended as a "safety net." It's generally a good idea to do your own
clean up, at least for normal application termination.
|
|