Destructor being called
<p>In the code below, the destructor of class <code>B</code> is called in Case 1 but not in Case 2, when the execution returns back to <code>main</code> from <code>fn()</code>. I don't understand this difference, since both are on heap memory when <code>A</code> is created with <code>new</code>. Could you please explain?</p>

<pre><code>class B {
public:
    B() {
        printf(" [B] COntsructor");
    }
    ~B() {
        printf(" [B] Destructor");
    }
};

class A {
public:
    A() { 
        printf(" [A] COntsructor");
    }
    ~A() { 
        printf(" [A] Destructor");
    }

    B Query() { return b; }    /// Case 1
    B* Query() { return &amp;b; }  /// Case 2

    B b;
};

void fn()
{
    A *a = new A();
    B b = a-&gt;Query();  // case 1
    B* b = a-&gt;Query(); // case 2
    return;
}

int _tmain(int argc, _TCHAR* argv[])
{
    fn();
    return 0;
}
</code></pre>
