Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update signal to remove a connection when disconnected #1462

Merged
merged 6 commits into from
May 12, 2020

Conversation

jslee02
Copy link
Member

@jslee02 jslee02 commented May 10, 2020

The current Signal design doesn't clean up disconnected connections until the signal calls the registered slots:

template <typename _Res, typename... _ArgTypes, template <class> class Combiner>
template <typename... ArgTypes>
_Res Signal<_Res(_ArgTypes...), Combiner>::raise(ArgTypes&&... _args)
{
std::vector<ResultType> res(mConnectionBodies.size());
auto resIt = res.begin();
for (auto itr = mConnectionBodies.begin(); itr != mConnectionBodies.end();)
{
if ((*itr)->isConnected())
{
*(resIt++) = (*itr)->getSlot()(std::forward<ArgTypes>(_args)...);
++itr;
}
else
{
mConnectionBodies.erase(itr++);
}
}
return Combiner<ResultType>::process(res.begin(), resIt);
}

or cleanupConnection() is explicitly called. This could lead to large memory consumption if we make many connections and disconnect them before emitting the signal or don't use cleanupConnection() in a right time.

This PR Signal to remove the disconnected connections when it's disconnected. This change keeps the backward compatibility because none of the public API isn't being changed.


Before creating a pull request

  • Document new methods and classes
  • Format new code files using clang-format

Before merging a pull request

  • Set version target by selecting a milestone on the right side
  • Summarize this change in CHANGELOG.md
  • Add unit test(s) for this change

@jslee02 jslee02 added this to the DART 6.10.0 milestone May 10, 2020
@jslee02 jslee02 mentioned this pull request May 10, 2020
2 tasks
@codecov
Copy link

codecov bot commented May 10, 2020

Codecov Report

Merging #1462 into master will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1462      +/-   ##
==========================================
- Coverage   58.21%   58.20%   -0.01%     
==========================================
  Files         412      412              
  Lines       29928    29911      -17     
==========================================
- Hits        17423    17411      -12     
+ Misses      12505    12500       -5     
Impacted Files Coverage Δ
dart/common/detail/ConnectionBody.cpp 100.00% <ø> (ø)
dart/common/Signal.cpp 81.48% <100.00%> (-2.90%) ⬇️
dart/common/detail/ConnectionBody.hpp 100.00% <100.00%> (ø)
dart/common/detail/Signal.hpp 100.00% <100.00%> (+1.75%) ⬆️
dart/collision/detail/UnorderedPairs.hpp 90.00% <0.00%> (-5.00%) ⬇️
dart/dynamics/EulerJoint.cpp 73.00% <0.00%> (+3.68%) ⬆️

@jslee02 jslee02 requested a review from mxgrey May 11, 2020 05:35
@jslee02 jslee02 merged commit b4da096 into master May 12, 2020
@jslee02 jslee02 deleted the signal_memory_leak branch May 12, 2020 04:09
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.

1 participant