I don't think, there is. Scripting languages tend to do their memory management by themselves, so that dangerous thinks like dangling references can't happen.Is there any function to force LUA to destroy the object even if it's still referenced at other places in the code?
So, you have essentially three choices
- Cleanup everywhere on game end (and game start, to be safe ;))
For example, is the UI having a reference really an issue? I would imagine that the UI object that holds the reference needs to be cleaned up anyway, so that reference to the discoveries will be gone anyway. And probably your seconds point of reference (which I didn't totally understand where this was) needs cleanup anyway, as well. - Only store in one place (the lib) and let the other places obtain a fresh reference from the lib when they need it.
Does the UI need to permanently store a reference? Instead it could do something likewhen it needs to display something discovery-related. So, that would even continue to work if the list of discoveries could change within the game.Code: Select all
local disc = Game.player:GetDiscoveries() -- or local disc = Discovery.GetDiscoveriesFor(Game.player)
- Add a level of indirection, e.g. have something like discoveries = { list = ... }, pass the reference to discoveries around and on cleanup, set discoveries.list = nil. (Actually, this is a variant of #2, as there is ever ony one reference to discoveries.list. I probably wouldn't go with this one, though. I can't tell why, but it feels "hacky".