asqbtcupid / unreal.lua

lua solution for UnrealEngine4
MIT License
300 stars 98 forks source link

_objectins2luatable how to recyle memory? #13

Closed mirchd closed 6 years ago

mirchd commented 6 years ago

Please help. _objectins2luatable table, how to set nil for lua GC? UUserWidget how to call Release, it does not has EndPlay?

thanks ~

asqbtcupid commented 6 years ago

_objectins2luatable table is "weak" table, It doesn't reference the objectins or luatable really.you shouldn't set nil manully.It will set nil autoly when no other "strong" table reference it.

What you have to do is to make sure no other strong table reference your UUserWidget ins. the next time lua garbage collection start,The memory will be recyled.

sometimes i will let some actor table reference uobject table.have a look to mmplayercontroller::beginplay or mmplayercontroller::InitFogMgr.

There is an api call "GC" for cppobjectbase. for an example, you call self:GC(AnotherCppObject),When "self" release, it will firstly call AnotherCppObject:Release(),It's done autoly,All you need to do is use self:GC().

When you want to link your UUserWidget ins to a cppactor (not implement lua, So it don't have GC function),you can use Link function. Have a look to animinstance.lua.When the target actor was Endplay or destroyed.It will autoly call your uobject's release function too.

mirchd commented 6 years ago

thank you very much

asqbtcupid commented 6 years ago

you are welcome,feel free to ask.After newversion is done(almost now),I will write documentation to explain how to use this plugin well.