[Home]Signals Notes

BOOST WIKI | RecentChanges | Preferences | Page List | Links List

This is for discussion of the Boost Signal library -- implementing signals & slots. Problems, suggestions, observations, etc.


Bug - mysterious multiple destructor calls

Testing out the Boost signals lib, I wrote:

    #include <boost/signal.hpp>
    #include <iostream>

    using namespace std;
    using namespace boost;

    struct X {
        void operator()(int val) { cout << "X <- " << val << endl; }
        X() { cout << "X constructor\n"; }
        ~X() { cout << "X destructor\n"; }
    };


    int main() {
        {
            cout << "   phase 1\n";
            signal<void (int)> sig;
            cout << "   phase 2\n";
            X x;
            cout << "   phase 3\n";
            sig.connect(x);
            cout << "   phase 4\n";
        }
        cout << "   phase 5\n";

        return 0;
    }

The following output is generated (gcc3.2.2 on Mandrake 9.1):

       phase 1
       phase 2
    X constructor

       phase 3
    X destructor
    X destructor
    X destructor
    X destructor
    X destructor
    X destructor
    X destructor
    X destructor
       phase 4
    X destructor
    X destructor
       phase 5

Why the multiple calls to X's destructor? I'd have expected just one, to match the single constructor. It looks like the signal lib is misbehaving.

Delving into it some, it actually looks like it's the function library which is causing the problem. Perhaps I'll eventually delve some more and isolate it.

    - Chuck

BOOST WIKI | RecentChanges | Preferences | Page List | Links List
Edit text of this page | View other revisions
Last edited May 16, 2003 10:30 am (diff)
Search:
Disclaimer: This site not officially maintained by Boost Developers