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

Memory management in Variants #502

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

JulienDoerner
Copy link
Member

fixes #493:

The abstractConditions added a property to the candidate on the rejection. Up to now it only adds the key Rejected. I added the module name as the default Value for the flag.

Also the variant (in which this key is stored), does not have the right destructor. If it is deleted, the type of the variant was not passed to the clear function. Therefore no deletion of the variant was possible. This leaded to the bug in the memory consumption.

Copy link
Member

@lukasmerten lukasmerten left a comment

Choose a reason for hiding this comment

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

I have not yet checked if it fixes the actual bug, but in principle it looks good to me. When I have verified the fix and my comments are addressed, I am happy to merge.

include/crpropa/Module.h Outdated Show resolved Hide resolved
include/crpropa/Module.h Outdated Show resolved Hide resolved
include/crpropa/module/Observer.h Show resolved Hide resolved
@@ -19,8 +19,7 @@ void Module::setDescription(const std::string &d) {

AbstractCondition::AbstractCondition() :
makeRejectedInactive(true), makeAcceptedInactive(false), rejectFlagKey(
"Rejected") {

"Rejected"), rejectFlagValue( typeid(*this).name() ) {
Copy link
Member

Choose a reason for hiding this comment

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

This would allow to check which module deactivated the candidate, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this is the idea. This function was already implemented earlier but the value was not set correctly. I think the module name as default is a good starting option, without going through all modules and set it by hand.

@JulienDoerner
Copy link
Member Author

The error also occurred for setting a property to a candidate, but only if the property is of type STRING.

for i in range(10_000_000): 
  c = Candidate() 
  c.setProperty("k", "str")

will give the same issue as discussed before. With the explicit delete this issue is solved.

The only remaining point is related to the AssocVector.

Python gives the warning
swig/python detected a memory leak of type 'Loki::AssocVector< std::string,crpropa::Variant > *', no destructor found.
when running the following example:

 c = Candidate()
 c.properties 
 c.isActive() 

One solution could be to change the AssocVector to std::map which should have the same functionality, or does someone no a difference why we should keep the AssocVector?

@rafaelab
Copy link
Member

Hi @JulienDoerner
In the last exchange you said there is a problem with AssocVector.
Is that fixed? Do you think the PR is good to go with this issue unaddressed?

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.

Memory management in BreakingCondition
3 participants