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

LuaDelegate连续多次绑定的内存泄漏问题 #70

Closed
zengdelang opened this issue Mar 2, 2019 · 0 comments
Closed

LuaDelegate连续多次绑定的内存泄漏问题 #70

zengdelang opened this issue Mar 2, 2019 · 0 comments

Comments

@zengdelang
Copy link

zengdelang commented Mar 2, 2019

在Lua中连续调用多次BInd一个代理,断点发现ULuaDelegate的析构函数只有Clear的时候会析构最后一次绑定的ULuaDelegate对象,其他对象未被回收,需要等到程序结束后,才会断点到ULuaDelegate的析构函数,建议在Bind的时候,先检查上次的绑定对象是否是ULuaDelegate对象,如果是将它释放``int LuaDelegate::Bind(lua_State* L)
{
CheckUD(LuaDelegateWrap, L, 1);

	auto object = UD->delegate->GetUObject();
	if (object)
	{
		ULuaDelegate* delegateObj = Cast<ULuaDelegate>(object);
		if (delegateObj)
		{
			delegateObj->dispose();
			LuaObject::removeRef(L, object);
		}
	}

	// bind luafucntion and signature function
	auto obj = NewObject<ULuaDelegate>((UObject*)GetTransientPackage(), ULuaDelegate::StaticClass());

#if WITH_EDITOR
obj->setPropName(UD->pName);
#endif
obj->bindFunction(L, 2, UD->ufunc);

	UD->delegate->BindUFunction(obj, TEXT("EventTrigger"));

	// add reference
	LuaObject::addRef(L, obj);

	lua_pushlightuserdata(L, obj);
	return 1;
}
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

1 participant