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

fix(Type): memory leak #61

Merged
merged 2 commits into from
Feb 14, 2025
Merged

fix(Type): memory leak #61

merged 2 commits into from
Feb 14, 2025

Conversation

mcakircali
Copy link
Contributor

replace raw ptr with unique_ptr
metkit::mars::Context::add and similar

@mcakircali mcakircali requested a review from danovaro February 14, 2025 14:04
@danovaro danovaro added the approved-for-ci Approved for CI run label Feb 14, 2025
Copy link
Member

@danovaro danovaro left a comment

Choose a reason for hiding this comment

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

looks good to me

@danovaro danovaro merged commit 9ff31aa into develop Feb 14, 2025
90 of 95 checks passed
@danovaro danovaro deleted the fix/mem-leak branch February 14, 2025 16:20
@@ -23,13 +29,13 @@ std::ostream& operator<<(std::ostream& s, const ContextRule& r) {
return s;
}

void Context::add(ContextRule* rule) {
Copy link
Member

@pmaciel pmaciel Feb 15, 2025

Choose a reason for hiding this comment

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

Note that there is a principle in this pattern, of passing pointers. The idea is if you pass a pointer you obviously tranfer the responsibility to manage it, hence tranfer ownership. Hence smart pointers aren't useful -- here, to replace the idom.

Now, maybe the function/method name itself isn't clear as it isn't "makeSomething" but when returning a pointer is an indication that it is a polymorphic type, and you don't loose type information this way either.

It is a pattern I didn't agree initially but learnt to be useful. It will be found in many places: eckit, atlas, mir, pgen, metview, mars-client (the classic one) and likely others. If we are to rewrite this, it is a massive change everywhere...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved-for-ci Approved for CI run
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants