Q: I have a dialog that I create using
GetNewDialog , passing in a pointer to the
dStorage parameter so that I can control the
memory used by the dialog. When I close the dialog, I follow
the guidelines in
Inside
Macintosh and call CloseDialog rather than
DisposeDialog . However, if my dialog has an
'ictb' resource associated with it, I find that
CloseDialog fails to dispose of the Dialog
Manager's copy of the 'ictb' , and my
application leaks. What should I do?
A: There are a number of things that you can do to solve
this problem. The best solution is to simply pass
nil to the dStorage parameter of
GetNewDialog (and dispose of your dialog by
calling DisposeDialog ). This will avoid the
memory leak (DisposeDialog does dispose of the
Dialog Manager's copy of your 'ictb' ) and, as
an added bonus, will make your application easier to port to
Carbon. Under Carbon, it is required that you let the
toolbox allocate storage for your windows and dialog by
passing nil to the storage parameter of the
creation routines.
Alternatively, you can replace your 'ictb'
resource with the more modern 'dftb' resource,
which supports most of the useful functionality of an
'ictb' and will not suffer from this bug.
The worst solution we can think of is to plug the memory
leak with the following code:
static void MyCloseDialog(DialogRef dlg)
{
AuxWinHandle auxWH;
Handle ictbH;
ictbH = nil;
if ( GetAuxWin(dlg, &auxWH) ) {
ictbH = (**auxWH).reserved;
}
CloseDialog(dlg);
if (ictbH != nil) {
DisposeHandle(ictbH);
}
}
|
Since many applications in use today assume that
CloseDialog does not dispose of the dialog's
'ictb' data, there is no plan for changing this
behavior.
[Jan 18 2000]
|