| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 1 | |
On 31 aug 2007, at 16.27, Steve M. Robbins wrote:
> On Fri, Aug 31, 2007 at 10:55:50AM +0200, Tommy Nordgren wrote:
>>
>> On 30 aug 2007, at 23.37, Steve M. Robbins wrote:
>
>>> The issue for me is to be able to clean up after Qt so that the
>>> Boost.Test leak detection shows only true leaks in my code. If
>>> I always get a report about these static objects, I'll never see
>>> the true leaks amongst the noise.
>
>> Try the following (at global scope, in the file implementing main)
>> class myAlloc {
>> public:
>> myAlloc() { allocate(); };
>> ~myAlloc() {};
>> static void allocate()
>> {
>> QObject obj;
>> };
>> };
>>
>> static myAlloc all;
>>
>> This will allocate and destroy a QObject instance before main is
>> run.
>> I think this will prevent the static pointers allocated by QObject
>> from
>> being recorded by the Boost unit tests.
>
> Clever! I hadn't thought of trying to allocate stuff before the
> leak detector starts.
>
> Unfortunately, this version doesn't work: the same "leaks" are
> detected. I don't know the precise details of the boost leak
> detection, but I suspect it is also statically initialized and you
> can't guarantee the order of static initializers.
>
> You said yesterday browsing the code showed some static objects being
> initialized. I had a quick look yesterday and didn't spot them. Do
> you recall what file or class was doing the allocation?
>
> Thanks,
> -Steve
>
Actually, I searched the code base, with a regular expression: static
[ \t]+[A-Za-z_0-9]+[ \t]*\*
Another point - check that you are using the correct version of the
headers, for your version of the boost
libraries. (Check to be done in the QT project file)
------
What is a woman that you forsake her, and the hearth fire and the
home acre,
to go with the old grey Widow Maker. --Kipling, harp song of the
Dane women
Tommy Nordgren
tommy.nordgren@xxxxxxxxx
--
[ signature omitted ]
On Fri, Aug 31, 2007 at 10:55:50AM +0200, Tommy Nordgren wrote:
> This will allocate and destroy a QObject instance before main is run.
> I think this will prevent the static pointers allocated by QObject from
> being recorded by the Boost unit tests.
So it turns out that the Boost.Test leak detection is implemented by
microsoft's heap allocation debugging code and there is a way to turn
on and off allocation debugging. I managed to make the "ignore the
first QObject creation" hack work as follows. Thanks for the
suggestion!
// Have Boost.Test ignore the memory leak from Qt static data.
class IgnoreQtStaticData
{
public:
IgnoreQtStaticData()
{
#if BOOST_MSVC
// Disable all heap debugging, allocate and destroy a QObject,
// then re-enable heap debugging.
int flags = _CrtSetDbgFlag( 0 );
allocate();
_CrtSetDbgFlag( flags );
#endif
}
static void allocate()
{
QObject obj;
};
};
static IgnoreQtStaticData ignoreQtStaticData;
Cheers
-Steve
P.S. I started a parallel thread in boost-users
http://lists.boost.org/boost-users/2007/08/30648.php
Attachment:
Attachment:
signature.asc
Description: Digital signature