Skip to content

Fix memory leak with tracked timers in triggers not being released on shutdown#4663

Merged
vadi2 merged 1 commit intoMudlet:developmentfrom
vadi2:fix-memoryleak-timer-tracking
Jan 25, 2021
Merged

Fix memory leak with tracked timers in triggers not being released on shutdown#4663
vadi2 merged 1 commit intoMudlet:developmentfrom
vadi2:fix-memoryleak-timer-tracking

Conversation

@vadi2
Copy link
Copy Markdown
Member

@vadi2 vadi2 commented Jan 20, 2021

Brief overview of PR changes/additions

Delete tracked timers when closing profile

Motivation for adding to Mudlet

Fix memory leak if you open/close profiles without shutting down Mudlet often

Other info (issues closed, discussion etc)

Fixes this leak:

8.14MB leaked over 761061 calls from
QHashData::allocateNode(int)
  in /tmp/.mount_MudletVSq2Ae/lib/libQt5Core.so.5
3.70MB leaked over 154084 calls from:
    QHash<>::createNode(unsigned int, QTimer* const&, QHashDummyValue const&, QHashNode<>**)
    QHash<>::insert(QTimer* const&, QHashDummyValue const&)
    QSet<>::insert(QTimer* const&)
    TTimer::TTimer(QString const&, QTime, Host*, bool)

@vadi2 vadi2 requested a review from a team as a code owner January 20, 2021 16:48
@vadi2 vadi2 requested a review from a team January 20, 2021 16:48
@add-deployment-links
Copy link
Copy Markdown

add-deployment-links bot commented Jan 20, 2021

Hey there! Thanks for helping Mudlet improve. 🌟

Test versions

You can directly test the changes here:

No need to install anything - just unzip and run.
Let us know if it works well, and if it doesn't, please give details.


TimerUnit::~TimerUnit()
{
for (auto&& timer : qAsConst(mQTimerSet)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that the right form? It seems to me that you are move constructing timer - but what is the qAsConst(...) doing - does it not prevent a copy being made of the items that are accessed in mQTimerSet so that suggests you are trying to both pull the items from the set and yet not modify the set...

😕

TBH If it were me doing this I'd just use:

    QMutableSetIterator<QTimer*> itPTimer(mQTimerSet);
    while (itPTimer.hasNext()) {
        delete itPTimer.next();
    }

fair enough that it is using a Qt Java style (?) iterator rather than a ranged for but it is clear how it works to me...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that is the old-school iterator style.

I am not constructing any timers, just looping the existing list.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤕 TBH I don't want to touch stuff like that - it may be nice and shiny and new-fangled but it confuses the hell out of me.... 👴

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Come on get in :)

Copy link
Copy Markdown
Contributor

@Kebap Kebap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems legit

@vadi2 vadi2 merged commit 946f4ce into Mudlet:development Jan 25, 2021
@vadi2 vadi2 deleted the fix-memoryleak-timer-tracking branch January 25, 2021 06:42
Chris7 pushed a commit to Chris7/Mudlet that referenced this pull request Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants