提交 47550624 编写于 作者: M maxwell_ding

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

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