Skip to content

Fix(deltaspin): memory leak error of deltaspin for nspin=4 - #7978

Merged
mohanchen merged 1 commit into
deepmodeling:developfrom
dyzheng:fix/deltaspin-cal-pre-hr-leak
Sep 17, 2026
Merged

mohanchen merged 1 commit into
deepmodeling:developfrom
dyzheng:fix/deltaspin-cal-pre-hr-leak

Conversation

@dyzheng

@dyzheng dyzheng commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Free pre_hr/B_I_data caches on cal_pre_HR() reinitialization

reset_dspin_operator() sets DeltaSpin::initialized=false, so the next cal_pre_HR() runs again on the same operator. It called pre_hr.clear() on a vector of raw HContainer pointers, which does not free the pointed-to objects, and it never reset B_I_data. In DFT+U+DeltaSpin LCAO runs (where reset_dspin_operator() is called when the constraints change) this leaked memory linearly with the number of reinitializations.

Delete the old HContainers before clearing pre_hr, and clear/resize B_I_data so unconstrained atoms do not keep stale overlap data.

Fixes #6524.

Unit Tests and/or Case Tests for my changes

  • Commands run:
  • Result summary:
  • Checks not run, with reason:

What's changed?

  • Example: brief summary of the user-visible or developer-facing change.

Governance Notes

  • INPUT/docs changes:
  • Core module impact:
  • Exceptions requested:

…ization

reset_dspin_operator() sets DeltaSpin::initialized=false, so the next
cal_pre_HR() runs again on the same operator. It called
pre_hr.clear() on a vector of raw HContainer pointers, which does not
free the pointed-to objects, and it never reset B_I_data. In
DFT+U+DeltaSpin LCAO runs (where reset_dspin_operator() is called when
the constraints change) this leaked memory linearly with the number of
reinitializations.

Delete the old HContainers before clearing pre_hr, and clear/resize
B_I_data so unconstrained atoms do not keep stale overlap data.

Fixes deepmodeling#6524.
@mohanchen mohanchen added collinear/non-collinear/SOC/delta-spin Issues related to SOC Refactor Refactor ABACUS codes Bugs Bugs that only solvable with sufficient knowledge of DFT labels Sep 17, 2026
@mohanchen
mohanchen merged commit 31c0829 into deepmodeling:develop Sep 17, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugs Bugs that only solvable with sufficient knowledge of DFT collinear/non-collinear/SOC/delta-spin Issues related to SOC Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory Leak

2 participants