[wx-dev] Curious about design choices
Robin Dunn
robin at alldunn.com
Thu Aug 9 10:14:23 PDT 2007
Nathan Ridge wrote:
> BB> NR> 2) What is the rationale for having to use Destroy() rather than
> BB> NR> "delete" to destroy an object created using "new"?
> BB>
> BB> VZ> This has already been answered I believe.
> BB>
> BB> Agreed: Destroy() waits for events sent to the object to be processed
> BB> before deleting the object. I guess my real question is, why can't the
> BB> code that waits for events be placed in the destructor?
>
> VZ> Because it needs to reenter the event loop to
> VZ> process these pending events and it would be
> VZ> really bad (as in "resulting in many unexpected
> VZ> and very difficult to diagnose bugs") if this happened
> VZ> from innocuously looking Destroy() call.
>
> I'm sorry, I'm not quite following you... does Destroy() re-enter the
> event loop or not?
It doesn't. For top-level windows it adds the window to a pending
delete list and returns immediately. That list is then checked in the
next idle event, which will happen after all pending events have been
processed.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wx-dev
mailing list