Memory leak using shared_ptr
Posted
by nabulke
on Stack Overflow
See other posts from Stack Overflow
or by nabulke
Published on 2010-04-29T09:02:52Z
Indexed on
2010/04/29
9:07 UTC
Read the original article
Hit count: 441
c++
|shared-ptr
Both code examples compile and run without problems. Using the second variant results in a memory leak. Any ideas why? Thanks in advance for any help.
Variant 1:
typedef boost::shared_ptr<ParameterTabelle> SpParameterTabelle;
struct ParTabSpalteData
{
ParTabSpalteData(const SpParameterTabelle& tabelle, const string& id)
:Tabelle(tabelle), Id(id)
{
}
const SpParameterTabelle& Tabelle;
string Id;
};
Variant 2:
struct ParTabSpalteData
{
ParTabSpalteData(const SpParameterTabelle& tabelle, const string& id)
:Id(id)
{
// causes memory leak
Tabelle2 = tabelle;
}
SpParameterTabelle Tabelle2;
string Id;
};
© Stack Overflow or respective owner