Retain Cycles in Verse

Do we need to worry about retain cycles in Verse? ie (weak vs strong)

ie
Each custom player class manages its own events, but sometimes the “game manager” device needs to know about those events.

Easy enough to throw in a game manager reference to the player, but then we have two objects with strong references to each other.

Alternatively, I could build a notification system to solve this, but I’m curious what the official Verse way is.

I suppose could also build a GameManagerDelegate system, but I would still want that to be a weak reference I think.

What do you think?

Looks like singletons are not possible, so a notification system is kind of pointless without a shared session

I think strong reference cycles are still possible. I’m not quit familiar with garbage collector languages and how they handle zombie objects. I would assume that if I create a cycle and do not break it, but remove all references to it from my code that I would potentially leak memory.

I don’t think verse has any official notation for weak references.

How do you give a game manager reference to the player ?

Also I think singletons are doable : I came up with a way to make singletons in Verse

I don’t know much about the core Verse loop but I’m assuming that all variables, listeners and threads get killed upon round ending. I guess you could test it with some code (?)

Cyclic references between objects are fine. Unreal Engine’s garbage collector finds objects that are no longer reachable by any code that could possibly run, and frees the memory.

4 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.