提交 47550624 编写于 作者: M maxwell_ding

fix(core): fix memory leak in Global singleton, test=develop

上级 c465a71c
...@@ -395,7 +395,7 @@ class KernelContext { ...@@ -395,7 +395,7 @@ class KernelContext {
class ContextScheduler { class ContextScheduler {
public: public:
static ContextScheduler& Global() { static ContextScheduler& Global() {
static auto* x = new ContextScheduler; static auto x = std::unique_ptr<ContextScheduler>(new ContextScheduler);
return *x; return *x;
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#pragma once #pragma once
#include <cstdarg> #include <cstdarg>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include "lite/core/tensor.h" #include "lite/core/tensor.h"
...@@ -43,7 +44,7 @@ typedef enum { ...@@ -43,7 +44,7 @@ typedef enum {
class DeviceInfo { class DeviceInfo {
public: public:
static DeviceInfo& Global() { static DeviceInfo& Global() {
static auto* x = new DeviceInfo; static auto x = std::unique_ptr<DeviceInfo>(new DeviceInfo);
return *x; return *x;
} }
...@@ -156,7 +157,7 @@ class Env { ...@@ -156,7 +157,7 @@ class Env {
typedef TargetWrapper<Type> API; typedef TargetWrapper<Type> API;
typedef std::vector<Device<Type>> Devs; typedef std::vector<Device<Type>> Devs;
static Devs& Global() { static Devs& Global() {
static Devs* devs = new Devs(); static auto devs = std::unique_ptr<Devs>(new Devs);
return *devs; return *devs;
} }
static void Init(int max_stream = 6) { static void Init(int max_stream = 6) {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "lite/core/op_registry.h" #include "lite/core/op_registry.h"
#include <list> #include <list>
#include <memory>
#include <set> #include <set>
namespace paddle { namespace paddle {
...@@ -248,7 +249,7 @@ KernelRegistry::KernelRegistry() ...@@ -248,7 +249,7 @@ KernelRegistry::KernelRegistry()
} }
KernelRegistry &KernelRegistry::Global() { KernelRegistry &KernelRegistry::Global() {
static auto *x = new KernelRegistry; static auto x = std::unique_ptr<KernelRegistry>(new KernelRegistry);
return *x; return *x;
} }
......
...@@ -48,7 +48,7 @@ class Factory { ...@@ -48,7 +48,7 @@ class Factory {
using creator_t = std::function<item_ptr_t()>; using creator_t = std::function<item_ptr_t()>;
static Factory& Global() { static Factory& Global() {
static Factory* x = new self_t; static auto x = std::unique_ptr<self_t>(new self_t);
return *x; return *x;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册