Skip to content

Conversation

@liincu4n
Copy link

@liincu4n liincu4n commented Jun 21, 2025

Description

This PR addresses resource consumption issues in the plot_RTFs and plot_results_LCs functions by adding input data size restrictions and ensuring proper closure of Matplotlib figures to prevent memory leaks.

Changes Made

  1. Input Data Size Restriction:

    • Added checks in plot_RTFs to limit the size of P_all and P_freqs arrays to 10,000,000 elements.
    • Added checks in plot_results_LCs to limit the size of freqs, P_DEISM_LC, and P_DEISM_LC_matrix arrays to 10,000,000 elements.
    • Throws ValueError if arrays exceed the limit, preventing excessive memory usage.
  2. Optimized Plot Closure:

    • In plot_RTFs, moved plt.close("all") outside the IF_SAVE_PLOT conditional blocks for both magnitude and phase plots to ensure figures are always closed.
    • In plot_results_LCs, added plt.close("all") after plt.show() for both magnitude and phase plots to prevent memory leaks.

Motivation

These changes improve the robustness of the plotting functions by:

  • Preventing crashes or slowdowns due to oversized input arrays.
  • Ensuring Matplotlib figures are properly closed, avoiding memory leaks in long-running scripts or when generating multiple plots.

Additional Notes

  • The input size limit (10M elements) can be adjusted if needed for specific use cases.
  • If further optimizations (e.g., data downsampling) are required, please provide feedback.

Please review and provide feedback. Let me know if additional tests or changes are needed!

…lot_results_LCs

1)added input array size checks in plot_RTFs and plot_results_LCs to prevent excessive memory usage (limit: 10M elements).
2)moved plt.close("all") outside conditional blocks in plot_RTFs and added it in plot_results_LCs to prevent memory leaks.
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