Re: question about destructors
Brought to you by:
set
From: Salvador E. T. <sal...@in...> - 2006-03-06 12:57:59
|
On 28/02/06 16:51, Petr B=EChan wrote: >Is there any reason why TGroup::~TGroup() doesn't call shutDown()? I'd >post it as bug, but it's so obvious that more likely there is some >really good reason that I don't see (wrong chaining of destructors with >some non-gcc compilers? I don't have too much experience with >portability in obscure environments, just gcc on linux and mingw). By >looking into other TV clones on the net it may be legacy from the >original borland source, but you said you don't aim to be 100% >compatible and besides changing it shouldn't bring any incompatibility. > =20 > >I know TV from ancient times when I worked in pascal. Recently I needed >to code UI for console applications so I looked for c++ counterpart to >TV I already knew, found this and did what I remembered as correct: >{ TDialog *dlg; > TProgram::deskTop->execView(dlg); > delete dlg; } >After coding 4 dialogs I thought that it's time to wonder if I have >memory management right, and of course I found that each dialog instance= >uses ~4kB memory which is not returned. And after little searching I >found that the correct way is to call CLY_destroy(dlg) instead of >standard c++ way of using destructors. > =20 > Yes. >Even Borland manual for destructor TGroup.done() (for pascal, I don't >have one for c++ TV) says "Hides the group using Hide, disposes of each >subview in the group, and finally calls the Done destructor inherited >from TView" in the description of TGroup destructor. As simple fix I >added the call to shutDown() into ~TView() and ~TGroup and the basic >dialogs now work as I expected (I didn't have lot of time to test it yet= >- it just compiles, runs and valgrind reports no leaks in views). I can >get a patch together if you are interested, after fixing rest of >shutDown()'s. And testing it a bit. > =20 > The need for destroy is because you could share the same objects between = different "containers", you could also have static items in a collection = (making destroy incorrect). In general: you need to use destroy when you need to delete an object=20 and what it contains, some times you don't want to destroy the contained = objects. SET --=20 Salvador Eduardo Tropea (SET). (Electronics Engineer) Visit my home page: http://welcome.to/SetSoft or http://www.geocities.com/SiliconValley/Vista/6552/ Alternative e-mail: se...@co... se...@ie...=20 Address: Curapaligue 2124, Caseros, 3 de Febrero Buenos Aires, (1678), ARGENTINA Phone: +(5411) 4759 0013 |