Do I need to destroy DCs and GCs after painting?

Hello,

I use DCs and GCs in my `on_paint` handlers. Do I need to destroy them
after use?

While we're on the subject, what about dialogs? Do I need to destroy
them after `EndModal`?

Thanks,
Ram.

Hello,

I use DCs and GCs in my `on_paint` handlers. Do I need to destroy them
after use?

They will automatically destroy themselves after their reference count drops to zero, usually after return from the scope that created them.

While we're on the subject, what about dialogs? Do I need to destroy
them after `EndModal`?

Yes. Dialogs are different because the C++ part of the window objects in wxPython hold a reference to the Python object, so you need to call Destroy() to deallocate the C++ object and break the cycle. Most window objects are owned by their parents and are destroyed automatically when the parent is, (or in the case of frames they destroy themselves when closed) but for dialogs they are meant to be used after they are closed (for accessing data values, etc.) so you have to explicitly destroy them.

···

On 12/15/10 8:50 AM, cool-RR wrote:

--
Robin Dunn
Software Craftsman

Thanks!

Ram.

···

On Wed, Dec 15, 2010 at 7:49 PM, Robin Dunn robin@alldunn.com wrote:

On 12/15/10 8:50 AM, cool-RR wrote:

Hello,

I use DCs and GCs in my on_paint handlers. Do I need to destroy them

after use?

They will automatically destroy themselves after their reference count drops to zero, usually after return from the scope that created them.

While we’re on the subject, what about dialogs? Do I need to destroy

them after EndModal?

Yes. Dialogs are different because the C++ part of the window objects in wxPython hold a reference to the Python object, so you need to call Destroy() to deallocate the C++ object and break the cycle. Most window objects are owned by their parents and are destroyed automatically when the parent is, (or in the case of frames they destroy themselves when closed) but for dialogs they are meant to be used after they are closed (for accessing data values, etc.) so you have to explicitly destroy them.

Robin Dunn