Skip to content

Conversation

@ChrisRackauckas-Claude
Copy link
Contributor

Summary

  • Fixes Pardiso leaks memory #593 by adding a finalizer to properly release Pardiso's internal memory
  • Prevents memory accumulation in long-running simulations with many linear solve calls
  • Follows the same cleanup pattern used by KLU solver

Problem

Pardiso allocates internal memory during ANALYSIS and NUM_FACT phases but never releases it, causing memory leaks when the solver is used repeatedly in long-running simulations.

Solution

Added a finalizer to the Pardiso solver object that:

  • Sets the phase to RELEASE_ALL (-1) when the solver is garbage collected
  • Calls pardiso with empty matrices to trigger the memory cleanup
  • Ensures internal buffers are properly released when LinearCache is garbage collected

Test plan

  • Added test script to verify the fix works correctly
  • Ran existing Pardiso tests to ensure no regression
  • Verified residual norms remain accurate after fix

The test creates multiple LinearProblems and solves them repeatedly, checking that:

  1. Solutions remain accurate (residual norm < 1e-10)
  2. Memory is properly released when caches are garbage collected

🤖 Generated with Claude Code

Pardiso allocates internal memory during ANALYSIS and NUM_FACT phases but never releases it, causing memory leaks in long-running simulations with many linear solve calls.

This commit adds a finalizer to the Pardiso solver object that:
- Sets the phase to RELEASE_ALL (-1) when the solver is garbage collected
- Calls pardiso with empty matrices to trigger the memory cleanup
- Follows the same pattern as KLU which uses finalizers for cleanup

The fix ensures that Pardiso's internal buffers are properly released when the LinearCache is garbage collected, preventing memory accumulation over time.

Fixes SciML#593

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@j-fu
Copy link
Contributor

j-fu commented Aug 21, 2025

Finalizers are now in Pardiso v1.1 .

ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/LinearSolve.jl that referenced this pull request Nov 14, 2025
…rization

This PR adds trimming tests to LinearSolve.jl, similar to PR SciML#734 in NonlinearSolve.jl.

## Summary
- Add `test/trim/` directory with infrastructure for testing trimming
- Add tests for LUFactorization, MKLLUFactorization, and RFLUFactorization
- Add "Trim" test group to CI configuration
- Tests only run on Julia 1.12+ (when trimming was introduced)

## Test Structure
The tests verify:
1. LUFactorization works correctly with pre-initialized cache
2. MKLLUFactorization works correctly with pre-initialized cache
3. RFLUFactorization works correctly with pre-initialized cache
4. Each implementation can be successfully compiled with \`juliac --trim\`

## Notes
- Trim tests only run on Julia 1.12+
- CI excludes trim tests on LTS and pre-release versions
- Tests use a custom environment in \`test/trim/\` to avoid conflicts

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
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.

Pardiso leaks memory

3 participants