Skip to content

Fix VTK actor leak due to incorrect cleanup guard in e-field visualization#1112

Open
suhr25 wants to merge 1 commit intoinvesalius:masterfrom
suhr25:fix/efield-actor-lifecycle
Open

Fix VTK actor leak due to incorrect cleanup guard in e-field visualization#1112
suhr25 wants to merge 1 commit intoinvesalius:masterfrom
suhr25:fix/efield-actor-lifecycle

Conversation

@suhr25
Copy link
Copy Markdown
Contributor

@suhr25 suhr25 commented Feb 20, 2026

Summary

Fixes a renderer cleanup issue in viewer_volume.py affecting MaxEfieldActor(), CoGEfieldActor(), and InitEfield().
Previously, actors were not always removed due to a coupled and condition, which could skip cleanup if one actor was None. This could leave valid actors in the renderer without Python references, causing a VTK-side memory/rendering leak.

Fix

  • Independent cleanup: Replaced paired checks with per-actor guards.
  • Lifecycle reset: Added = None after RemoveActor() to release references.
  • Consistency: Aligned with the existing pattern used for edge_actor.

Before

if self.max_efield_vector and self.ball_max_vector is not None:
    self.ren.RemoveActor(self.max_efield_vector)
    self.ren.RemoveActor(self.ball_max_vector)

After

if self.max_efield_vector is not None:
    self.ren.RemoveActor(self.max_efield_vector)
    self.max_efield_vector = None

if self.ball_max_vector is not None:
    self.ren.RemoveActor(self.ball_max_vector)
    self.ball_max_vector = None

Verification

Repeated InitEfield() calls keep actor count stable (self.ren.GetActors().GetNumberOfItems()), with no memory growth or visual changes.

Replace broken AND-gated cleanup guards with independent per-actor
is-not-None checks in MaxEfieldActor, CoGEfieldActor, and InitEfield.
Add missing = None resets after RemoveActor so VTK objects are released
promptly and the renderer does not accumulate orphaned actors across
efield reloads and navigation updates.

Signed-off-by: suhr25 <suhridmarwah07@gmail.com>
@suhr25
Copy link
Copy Markdown
Contributor Author

suhr25 commented Feb 20, 2026

Hi @paulojamorim,
Fixes a cleanup issue where actors weren’t removed if one of the pair was None, causing accumulation over time.
Now each actor is removed independently and properly reset, preventing renderer and memory growth.

@rmatsuda rmatsuda requested a review from sotodela February 23, 2026 07:31
@suhr25
Copy link
Copy Markdown
Contributor Author

suhr25 commented Feb 26, 2026

Hi @sotodela @paulojamorim,

Just following up on this PR when you have a moment.
Thanks!

@suhr25
Copy link
Copy Markdown
Contributor Author

suhr25 commented Mar 3, 2026

Hi @sotodela @paulojamorim,
Can you please review this PR.
Thanks!

@suhr25
Copy link
Copy Markdown
Contributor Author

suhr25 commented Mar 7, 2026

Hi @sotodela @paulojamorim,
Just a follow up message
Kindly review this PR.
Thanks!

@suhr25
Copy link
Copy Markdown
Contributor Author

suhr25 commented Mar 16, 2026

Hi @sotodela @paulojamorim,
Just a follow up message
Please review this PR.
Thanks!

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