Boost logo

Boost Users :

Subject: [Boost-users] Losing memory connecting multiple signals to a passed slot_type
From: COBryan (cobryan_at_[hidden])
Date: 2009-11-17 13:18:11


Hi, I've been losing memory when using Boost::Signal. I cannot find anywhere
in forums and documentation if it's legal to use a passed slot_type multiple
times, so I feel that may be the issue, but was wondering if someone here
could either verify that or otherwise help me fix my problem.

I have a PageManager that inherits from boost::signals::trackable. From
this PageManager I make this call:
-------------------------
   texthandle[i].getPhrases
   (
   boost::bind( &PageManagerCommon::shortcutHandler, this, i )
   );
-------------------------
TextHandle also inherits boost::signals::trackable. To test the leak, I
replaced TextHandle::getPhrases with the following code:
-------------------------
    typedef boost::signal0<void> PhraseSignalType;

    struct PhraseType
    {
        PhraseSignalType signal;
    };

    void TextHandle::getPhrases
        (
        const PhraseSignalType::slot_type& aSlot //!< The slot to connect
the phrase signals to
        ) const
    {
        PhraseType *phrase;
        std::list<PhraseType*> phraseList;
        std::list<PhraseType*>::iterator phraseIter;

        for(int i = 0; i < 50; i++)
        {
            phrase = new PhraseType;
            phrase->signal.connect(aSlot);
            phraseList.push_back(phrase);
        }
        for(phraseIter = phraseList.begin(); phraseIter != phraseList.end();
phraseIter++)
        {
            delete *phraseIter;
        }
        phraseList.clear();
        return;
   }
-------------------------

Now, what I expect to happen is to create 50 phrases, push them into a list,
then iterate through the list destroying these phrases. When the phrase is
destroyed, the signal should disconnect and clean itself up. Instead, my
memory usage simply goes up. We use an allocator that tracks 'memory
handles,' and it seems that the number of unfreed handles is always the
number of phrases - 1, so in this case we had 49 handles that weren't
freed. I feel like this has something to do with using the passed slot_type
for multiple connects, but can't find anywhere saying that I can't do that.

I would appreciate any suggestions.

Thanks,
Chris

-- 
View this message in context: http://old.nabble.com/Losing-memory-connecting-multiple-signals-to-a-passed-slot_type-tp26394902p26394902.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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