Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory leak #137

Closed
guker opened this issue Sep 15, 2017 · 3 comments
Closed

memory leak #137

guker opened this issue Sep 15, 2017 · 3 comments

Comments

@guker
Copy link

guker commented Sep 15, 2017

inline void Mat::release()
{
if (refcount && NCNN_XADD(refcount, -1) == 1)
fastFree(data);

dims = 0;
data = 0;

w = 0;
h = 0;
c = 0;

cstep = 0;

refcount = 0;

}

假设Mat的refcount != 1,则不会执行fastFree,而此时data=0,则内存泄漏

@nihui
Copy link
Member

nihui commented Sep 15, 2017

refcount > 1 有其他 Mat 共享这个 data,所以不能 fastFree ...

@nihui nihui closed this as completed Sep 16, 2017
@kobebry80
Copy link

为什么判断是NCNN_XADD(refcount, -1) == 1,而不是NCNN_XADD(refcount, -1) == 0? 不是引用计数为0的时候释放内存么?

@nihui
Copy link
Member

nihui commented Dec 16, 2018

NCNN_XADD 返回的是 XADD 之前的值

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants