WeaselGames / godot_luaAPI

Godot LuaAPI
https://luaapi.weaselgames.info
Other
391 stars 30 forks source link

Bug Report: Leaked instance: LuaAPI:id #66

Closed Trey2k closed 1 year ago

Trey2k commented 1 year ago

Describe the bug Memory leak cause when ever a new instance and the LuaAPI is created. Get the following warning in stderr Leaked instance: LuaAPI:id

To Reproduce call luaAPI.new() and store it in a variable

extends Node2D

func _ready():
    var lua = LuaAPI.new()
    var err = lua.do_string("print('test')")
    if err is LuaError:
        print("ERROR %d: " % err.type + err.msg)
    get_tree().quit(0)

Expected behavior To not leak.

Enviromint (please complete the following information):

Additional context It has to do with ObjectDB::remove_instance not being called. Im not familiar enough with this part of godot yet to say why that is.

Trey2k commented 1 year ago

I logged all object IDs passed to ObjectDB::add_instance, and the ID listend in the Leaked instance was not there. So I am unsure how else it could be added to object_slots.

Trey2k commented 1 year ago

The issue was occurred because LuaAPI which stores a LuaState was stored by Ref in LuaState. LuaState would not free until LuaAPI's destructor was called. Which was not allowed to happen since it was stored in a safe Ref. Fixed by changing to a pointer which I think should be safe enough here. Fixed in a5b895150000ff8f46522c2af651c3e08c02efe2 will merge with #65