diff --git a/eeschema/sim/ngspice.cpp b/eeschema/sim/ngspice.cpp index 7cdaade5b9..ffebf5269e 100644 --- a/eeschema/sim/ngspice.cpp +++ b/eeschema/sim/ngspice.cpp @@ -705,4 +705,10 @@ void NGSPICE::validate() } +void NGSPICE::Clean() +{ + Command( "destroy all" ); +} + + bool NGSPICE::m_initialized = false; diff --git a/eeschema/sim/ngspice.h b/eeschema/sim/ngspice.h index f06805203e..d613c030f8 100644 --- a/eeschema/sim/ngspice.h +++ b/eeschema/sim/ngspice.h @@ -97,6 +97,9 @@ public: ///< @copydoc SPICE_SIMULATOR::GetNetlist() virtual const std::string GetNetlist() const override final; + ///< @copydoc SIMULATOR::Clean() + void Clean() override final; + private: void init(); diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index 6c267a3d03..ef9f8de931 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -481,6 +481,8 @@ void SIM_PLOT_FRAME::StartSimulation( const wxString& aSimCommand ) { updateTuners(); applyTuners(); + // Prevents memory leak on succeding simulations by deleting old vectors + m_simulator->Clean(); m_simulator->Run(); } else @@ -1641,6 +1643,9 @@ void SIM_PLOT_FRAME::doCloseWindow() if( m_simulator->IsRunning() ) m_simulator->Stop(); + // Prevent memory leak on exit by deleting all simulation vectors + m_simulator->Clean(); + // Cancel a running simProbe or simTune tool m_schematicFrame->GetToolManager()->RunAction( ACTIONS::cancelInteractive ); diff --git a/eeschema/sim/simulator.h b/eeschema/sim/simulator.h index 6b1bc44770..1cc98e8210 100644 --- a/eeschema/sim/simulator.h +++ b/eeschema/sim/simulator.h @@ -99,6 +99,12 @@ public: */ virtual bool IsRunning() = 0; + /** + * Cleans simulation data (i.e. all vectors) + * + */ + virtual void Clean() = 0; + protected: ///< Model that should be simulated. std::shared_ptr m_simModel;