From f50e701b3b60d9f9f2ccf661caad1acbc2e6fe1a Mon Sep 17 00:00:00 2001 From: xujiaqi01 <173596896@qq.com> Date: Wed, 25 Sep 2019 23:39:18 +0800 Subject: [PATCH] fix memory leak in HogwildWorker (#19956) fix memory leak in HogwildWorker, whose ops are explicitly deleted in destructor --- paddle/fluid/framework/device_worker.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/framework/device_worker.h b/paddle/fluid/framework/device_worker.h index 34702df5291..6164953083b 100644 --- a/paddle/fluid/framework/device_worker.h +++ b/paddle/fluid/framework/device_worker.h @@ -151,7 +151,12 @@ class CPUWorkerBase : public DeviceWorker { class HogwildWorker : public CPUWorkerBase { public: HogwildWorker() {} - virtual ~HogwildWorker() {} + virtual ~HogwildWorker() { + for (OperatorBase* op : ops_) { + delete op; + } + std::vector().swap(ops_); + } virtual void Initialize(const TrainerDesc& desc); virtual void TrainFiles(); virtual void TrainFilesWithProfiler(); -- GitLab