On 30 aug 2007, at 21.12, Steve M. Robbins wrote:
Hi,
I'd appreciate some advice using the Boost unit testing library with
Qt classes.
I'm using MSVC 8.0 on windows XP.
My naive attempts so far suggest that simply creating and destroying a
QObject leaks memory. At least, that's what boost tells me. Consider
the following test program:
#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
#include <Qt/qobject.h>
BOOST_AUTO_TEST_CASE( example )
{
BOOST_CHECK_EQUAL( 1, 1 );
QObject obj;
}
It builds and runs fine, except that memory leaks are detected; output
is as follows:
Running 1 test case...
*** No errors detected
Detected memory leaks!
Dumping objects ->
{271} normal block at 0x003FC5A0, 20 bytes long.
Data: < > 00 CD CD CD 00 00 00 00 00 00 00 00 00 00
00 00
{270} normal block at 0x003FC510, 96 bytes long.
Data: <$ g ? 3&g> 24 C9 1A 67 D8 C4 3F 00 00 00 00 00 B4 33
26 67
{269} normal block at 0x003FC4D8, 8 bytes long.
Data: <0 g ? > 30 C9 1A 67 10 C5 3F 00
{268} normal block at 0x003FC498, 20 bytes long.
Data: < > 00 CD CD CD 00 00 00 00 00 00 00 00 00 00
00 00
{267} normal block at 0x003FC438, 48 bytes long.
Data: < ? > 01 00 00 00 D8 C4 3F 00 00 CD CD CD 00 00
00 00
Object dump complete.
If I comment out the "QObject obj" line, no leaks are detected. So I
presume Qt is at fault, here. What's being leaked? Is there a way to
clean it up?
Thanks,
-Steve
I've browsed the source code. There appears to be some static object
pointers,
that are allocated when a QObject-derived class is first allocated.
Such objects won't be deallocated until the heap is thrown into the
bitbucket
on process termination.
To check if you have a leak or not:
#define BOOST_AUTO_TEST_MAIN
#include <boost/test/auto_unit_test.hpp>
#include <Qt/qobject.h>
BOOST_AUTO_TEST_CASE( example )
{
BOOST_CHECK_EQUAL( 1, 1 );
QObject obj;
QObject obj2; // If there are a true leak, the unit test will now
show twice the amount of leaked memory.
}
------------------------------------------------------
"Home is not where you are born, but where your heart finds peace" -
Tommy Nordgren, "The dying old crone"
tommy.nordgren@xxxxxxxxx
--
To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
"unsubscribe" in the subject or the body.
List archive and information: http://lists.trolltech.com/qt-interest/
|