Cleaning unused UMG Widget References... Am I hacking?

To ease comunication from the entire game with the UMG I’m doing all the widget manipulation through the HUD BP plus a widget that just “holds” the desired elements as childs, but there are not internal references on this One2RuleAll guy, I just get his Canvas borrowed and add childs created (and referenced) on the BP, I got this way a method to “eject” the unused widgets from the HUD by calling RemoveFromParent() from their “HUDhosted” variables.

OK, it’s working.

BUT… Some from these widgets are just what I called “one timers”, what means that after displayed to the player they’ll just appears again on most cases after a long, long time. I’ve called the RemoveFromParent, they get out from Screen but their references still “alive” for a very long time. (I did a test with the “?Is Valid” Node on the HUDTick).

To try to contour the situation I’m Setting these variables with none attached on then:


It’s working through the “?IsValid” test, but I would like to know if this is either “nulling” it or in really benefiting the Garbage Collector in some way by don’t keeping more any asset reference.

Thank you.

They’re kept alive as long as anyone holds a reference to the UObject pointer,so nulling out your member variable pointing to them will allow the GC to clean them up.

I didn’t found a “NULL”, “nullify”, or anything alike node on BPs, is this “Set” with nothing tied to it acting as a “Null that”? On my first try, I thought it will throw an error as the ones we get on some Nodes that does requires a Target tied to a pin. :smiley:

I would guess as just as you make a null check with a compare to nothing, seting a null is setting a object to nothing.