Boost Users :
Subject: [Boost-users] shared_ptr leaking memory and crashing / gcc 3.4.6
From: Michael (boost_at_[hidden])
Date: 2008-10-17 18:44:14
I figured that shared_ptr (boost 3.4, but I don't think this is really a
boost problem) will lose memory in the following example
typedef boost::shared_ptr<X> XRef;
int main(int argc, char** argv)
myX = getx();
Compile: g++ -I/usr/local/include test.C -o test
On every iteration of the while loop it loses memory and after approx. 1
million iterations it dies with signal 10 or 11.
Changing that pattern to
XRef y = getx();
myX = y;
fixes the problem (I assume in that case it will call shared_ptrs copy
constructor instead of its assignment operator).
Platform is FreeBSD 6, gcc 3.4.6. It only happens when compiled like
above (without optimization). On optimization levels 2 and above (-O2)
it works ok. Maybe somebody using gcc 3.4 can check if this also happens
on other platforms. gcc 4 works ok without any issues, so I assume this
is a compiler problem. It might still be a good idea to put a warning in
the documentation about this.
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