FLTK logo

Re: [fltk.general] Examples create a ton of dynamic visual objects

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: Examples create a ton of dynamic visual objects Albrecht Schlosser Sep 29, 2016  
 
On 29.09.2016 22:11 Juan Dent wrote:

Following the Tabs example, the main() function creates a bunch of GUI
objects using new but never deletes them!!

This is a bad approach!!


Please enlighten me!

You may not want to hear (read) this because your teachers taught you a different story, but ...

Deleting GUI elements at the end of the program is not only not necessary, it can also slow down your program when someone clicks the "Exit" button or menu. Executing destructors takes some time, and normally nobody wants to wait for that until the program _really_ exits. Note that this is only true if the d'tors don't need to reset any other program state like open files or such. If your widgets hold data that need to be flushed at exit, running the d'tors may be essential.

That said, all resources required by GUI elements are free'd at program exit anyway, so there's no need to do this explicitly.

And, BTW, if you really wanted to delete all GUI elements then you could just 'delete foo_window;' after Fl::run() returns. This would delete all GUI elements included in foo_window (see Fl_Window docs).

Something like this would do the trick:

  foo_window->show(argc, argv);
  Fl::run();
  delete foo_window;
  return 0;
}

In this case the CPU time difference can't be measured reliably, but anyway: it's useless to do this, and we don't recommend this in the general case. See exceptions above.

--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.