提交 2dd9e51e 编写于 作者: T Tensor Tang

Merge branch 'develop' into 'develop'

fix memory leak for tensor buffer and context

See merge request paddlepaddle/paddlelitearmbackend!8
...@@ -65,6 +65,8 @@ class Buffer { ...@@ -65,6 +65,8 @@ class Buffer {
TargetCopy(target_, data_, other.data_, nbytes); TargetCopy(target_, data_, other.data_, nbytes);
} }
~Buffer() { Free(); }
private: private:
// memory it actually malloced. // memory it actually malloced.
size_t space_{0}; size_t space_{0};
......
...@@ -34,7 +34,6 @@ class Any { ...@@ -34,7 +34,6 @@ class Any {
CHECK(type_ == typeid(T).hash_code()); CHECK(type_ == typeid(T).hash_code());
} else { } else {
type_ = typeid(T).hash_code(); type_ = typeid(T).hash_code();
data_ = new T;
deleter_ = [&] { delete static_cast<T*>(data_); }; deleter_ = [&] { delete static_cast<T*>(data_); };
} }
data_ = new T; data_ = new T;
...@@ -55,10 +54,16 @@ class Any { ...@@ -55,10 +54,16 @@ class Any {
bool valid() const { return data_; } bool valid() const { return data_; }
~Any() {
if (valid()) {
deleter_();
}
}
private: private:
static size_t kInvalidType; static size_t kInvalidType;
size_t type_{kInvalidType}; size_t type_{kInvalidType};
void* data_{}; void* data_{nullptr};
std::function<void()> deleter_; std::function<void()> deleter_;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册