|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Freeing memoryI have a rather basic question. I have several FXDialogBox windows. In
the header files I declare pointers and in the constructor I allocate the memory. In the quit method of some of these FXDialogBox I delete the memory and in some I don't (sloppy programming I guess). I see no difference in memory allocation or leaking. Am I doing something wrong or is the memory automatically cleaned up by fox? Also, many times my destructor is never called...does this make sense? Thanks, John S ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ Foxgui-users mailing list Foxgui-users@... https://lists.sourceforge.net/lists/listinfo/foxgui-users |
|
|
Re: Freeing memoryOn Thursday 11 June 2009, Selverian, John wrote:
> I have a rather basic question. I have several FXDialogBox windows. In > the header files I declare pointers and in the constructor I allocate > the memory. In the quit method of some of these FXDialogBox I delete > the memory and in some I don't (sloppy programming I guess). I see no > difference in memory allocation or leaking. Am I doing something wrong > or is the memory automatically cleaned up by fox? Also, many times my > destructor is never called...does this make sense? FOX tries to delete memory, yes. But there is no reference counting or garbage collection, so it can only delete things that it knows it can delete: 1) Parent widgets delete child widgets. 2) Entire widget tree is deleted by FXApp. But: 1) Shared resources like icons, fonts, are NOT deleted, since multiple references may exist [exception: stock icons and cursors which are created by FXApp]. A simple rule-of-thumb is to delete all icons/fonts/etc. that you create in youre dialog's constructor, in your dialog's destructor. In FOX 1.7, you now have FXAutoPtr which makes this quite easy: class MyDialog : public FXDialog { FXAutoPtr<FXIcon> buttonIcon; }; The idea with FXAutoPtr is, it behaves like a regular pointer but acts as sole owner of the object it points to, and thus when FXAutoPtr is destroyed then the thing it points to also is destroyed. So declaring your icon-variables as FXAutoPtr<FXIcon> instead of FXIcon* will eliminate the need to write explicit delete statements in your destructors. Hope this helps, - Jeroen ------------------------------------------------------------------------------ Crystal Reports - New Free Runtime and 30 Day Trial Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects _______________________________________________ Foxgui-users mailing list Foxgui-users@... https://lists.sourceforge.net/lists/listinfo/foxgui-users |
| Free embeddable forum powered by Nabble | Forum Help |