Boost logo

Boost Users :

From: Brad Anderson (eco.was.too.short_at_[hidden])
Date: 2008-07-25 19:41:12


On Fri, Jul 25, 2008 at 5:28 PM, Matthias Troyer <troyer_at_[hidden]>
wrote:

> On 25 Jul 2008, at 13:53, Brad Anderson wrote:
>
> I'm getting memory leaks when deserializing objects and I can't figure out
>> what I'm doing wrong. I'm using VC++ 2005. I've boiled it down to the
>> following code:
>>
>
> Just a quick guess:
>
> //virtual ~Base() { } // uncommmenting this causes leaks to disappear
>>
>
> The base class needs a virtual destructor, thus uncommenting this is
> needed.

I solved my problem seconds before I got your message :). I had actually
done that in what I thought was the class giving issue but it turns out I
had several base classes that were missing virtual destructors so that fix
didn't appear to work because I was still getting tons of leaks.

I am curious, though, about why the leaks only happened in when I
deserialized and not in any of the other instances I created myself. Does
shared_ptr perform some kind of trickery to detect the type to delete
through, even when the shared_ptr is typed for the base class?

> Matthias
>
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net