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

BUG: Fix memory leaks by moving progress from the heap to the stack #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented Jul 2, 2024

Declaring those two local ProgressReporter objects on the stack (instead of on the heap) may benefit run-time performance. But moreover, it fixes two memory leaks (missing delete progress).

Declaring those two local `ProgressReporter` objects on the stack (instead of
on the heap) may benefit run-time performance. But moreover, it fixes two
memory leaks (missing `delete progress`).
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jul 2, 2024
Declaring `ProgressReporter` on the stack (instead of on the heap) may benefit run-time performance. But moreover, it fixes a memory leak.

- Corresponds with pull request richardbeare/parabolicMorphology#11 "BUG: Fix memory leaks by moving `progress` from the heap to the stack"
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Jul 2, 2024
Declaring `ProgressReporter` on the stack (instead of on the heap) may benefit run-time performance. But moreover, it fixes a memory leak.

- Corresponds with pull request richardbeare/parabolicMorphology#11 "BUG: Fix memory leaks by moving `progress` from the heap to the stack"
@N-Dekker
Copy link
Contributor Author

N-Dekker commented Jul 4, 2024

@richardbeare
Copy link
Owner

richardbeare commented Jul 4, 2024 via email

@N-Dekker
Copy link
Contributor Author

N-Dekker commented Jul 4, 2024

Minimally - I'm hoping to look at your mods when I'm back from leave.

Thanks, @richardbeare In the mean time, I'll try to already get my proposed ParabolicMorphology adjustments into https://github.com/SuperElastix/elastix and https://github.com/InsightSoftwareConsortium/ITKParabolicMorphology, hoping that they will eventually find their way into your repo!

@richardbeare
Copy link
Owner

richardbeare commented Jul 6, 2024

The remote module in ITK references InsightSoftwareConsortium/ITKParabolicMorphology, rather than my repo. I'll have a look at what you've proposed.

The ITK migration guide suggests we should be moving to ProgressTransformer. Perhaps this is the time to make the move.

The changes in other PRs look OK.

@N-Dekker
Copy link
Contributor Author

N-Dekker commented Jul 7, 2024

Thanks @richardbeare Of course, I can also submit the other PRs to your richardbeare/parabolicMorphology repo (rather than just to InsightSoftwareConsortium/ITKParabolicMorphology and elastix). What would you suggest?

@N-Dekker
Copy link
Contributor Author

N-Dekker commented Jul 7, 2024

The ITK migration guide suggests we should be moving to ProgressTransformer. Perhaps this is the time to make the move.

Thanks @richardbeare Honestly I didn't know about ProgressTransformer versus ProgressReporter. Indeed I see now at https://github.com/InsightSoftwareConsortium/ITK/blob/master/Documentation/docs/migration_guides/itk_5_migration_guide.md?plain=1#L374-L379

Since itk::ProgressReporter does not work well with the new threading model, it should be replaced by itk::ProgressTransformer. This only applies to classes which use GenerateData() method, and either have multiple ParallelizeRegion calls or a long single-threaded section.

Still not sure if it applies to ParabolicErodeDilateImageFilter. Does your filter use "the new (ITK) threading model"? It does call DynamicMultiThreadingOff(), so then, doesn't it still use the older threading model? It certainly does not have ParallelizeRegion calls. What do you think?

Anyway, I would propose to just fix those two obvious memory leaks of local ProgressReporter objects for now, and maybe consider moving to ProgressTransformer afterwards.

@richardbeare
Copy link
Owner

I've confirmed the leak existed and is fixed by this modification. (Had hoped that the use of auto would invoke the smart pointer side of things and handle the problem).
I think this PR needs to be rebased off the current head - the InsightConsortium hosted fork was ahead of mine.

@N-Dekker
Copy link
Contributor Author

N-Dekker commented Jul 8, 2024

I've confirmed the leak existed and is fixed by this modification.

Thank you @richardbeare, for confirming the memory leak, as well as the fix!

I think this PR needs to be rebased off the current head - the InsightConsortium hosted fork was ahead of mine.

Well, I think it's OK already. The corresponding PR that I submitted to the InsightConsortium is already on top of the head of Insight's main branch:

Can you possibly merge the pull request (Insight PR #45) at the Insight repo?

@richardbeare
Copy link
Owner

I don't have control of the InsightConsortium fork - I guess they'll get to it soon. I'll sync my fork with theirs once the PR is merged.

@N-Dekker
Copy link
Contributor Author

N-Dekker commented Jul 9, 2024

I don't have control of the InsightConsortium fork - I guess they'll get to it soon. I'll sync my fork with theirs once the PR is merged.

Thanks @richardbeare. I don't mind asking the maintainers of the InsightConsortium fork, but are you sure you don't have permission to merge? As far as I can see, you did merge the very first PR to the InsightConsortium fork! Back in 2015!

(FYI, I regularly contribute to ITK, so I'm familiar with the other maintainers 😃. We also collaborate on elastix/ITKElastix.)

@richardbeare
Copy link
Owner

@thewtex I'm very out of date with the PR process - are you able to look into these updates?

@thewtex
Copy link
Contributor

thewtex commented Jul 12, 2024

@richardbeare I went ahead and merged them. If the PR's look good to you, feel free to just hit the green PR merge button.

When we want to push new Python packages, we currently have to manually bump the version -- done here: InsightSoftwareConsortium#47

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