Mark Dootson wrote:
Hi,
Tests suggested passed on Win32 and Linux - but failed on Mac.
Looking into the underlying implementations, on MSWin and Linux, the
wxOverlay object holds on to a reference to a wxBitmap - which worked OK.
On wxMac however, the implementation holds onto a reference to the
client window and a mac graphics object representing the screen ( I
think ).
I've removed the CLONE and DESTROY methods for both Wx::Overlay and
Wx::DCOverlay leaving Perl to do the default thing.
My understanding is that this should be OK - the only effect being that
Wx::Overlay and Wx::DCOverlay become like most other GUI objects - only
accessible in the main thread. They would not have been usable in
working code outside the main thread anyway.
The point of the CLONE/DESTROY pair in wxPerl classes is avoiding
crashes/double free errors. None of the classes that have a
CLONE/DESTROY pair work inside a thread.
The code now passes tests - but that doesn't say much as there are now
no CLONE and DESTROY methods.
The DESTROY method is needed, otherwise the objects will leak. Once
you have a DESTROY, you need a CLONE to work with threads, without it:
- an object is allocated
- a thread starts and copies the Perl-level object
- the thread ends, runs DESTROY methods and frees the C++ object
- the main program ends, tries to free the already-freed C++ object
and crashes
the CLONE used by wxPerl avoids the first free (the one at thread end)
by NULL-ing all wxPerl objects inside a thread.
HTH,
Mattia