Boost logo

Boost Users :

Subject: Re: [Boost-users] [SmartPtr] Memory Leak Perhaps
From: Binglong Xie (binglongx_at_[hidden])
Date: 2010-09-19 21:46:54


> Well, my only suspicion is about the fact that I store "this" pointers in
> my shared_ptr's. However, those objects are dynamically allocated by
> myself, namely, they are not of automatic storage type anyway. In other
> words, my row pointer and "this" -- which themselves are different
> objects -- both point to the same memory dynamically allocated by myself.
> Furthermore, my following observation goes against this guess: (This is
> available above too.)

Why do you need to use two semantically different pointers to point to the
same piece of dynamic memory?

> Actually it does allocate memory for other objects (which are stored in
> the same container). But, I have tested that and the result is that
> everything -- including this extra allocation -- works perfectly fine JUST
> if I drop the insertion of this very specific object in the same
> container.
> Am I missing anything? I would especially be keen on knowing whether you
> see any problems in storing "this" pointers of my own dynamically
> allocated objects in shared_ptr's.

You may need to show how "specific" the object is -- sometimes a few lines
of code are better than paragraphs of words.

Why do you need to put a "this" pointer in a shared_ptr? When you can get a
hand on "this", you are in the member function of the class. Basically that
means your instance has already been created. The client creating the
instance should probably manage the life cycle of this instance. I would say
it's normally the responsibility of the client to put the instance pointer
into a shared_ptr if it's not allocated on the stack. Again, you may want to
paste your code to make the discussion easier.
 


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