Garbage Collection and widgets

If I make an inventory menu with a nested grid of 16 slots and those slots are an instanced “slotwidget” in say a 4 by 4 grid I get 16 instances of that slot widget. when I close the menu I remove the inventory menu from its HUDMASTER canvas panel via ‘remove from parent’… if I open and close the inventory menu 100 times and look in the editor window for the slotwidget drop down - I see 1600 instances of those slot widgets. There doesn’t seem to be a “destroy” widget and 'remove from parent seems to be the correct method. Does that mean Garbage collection willgracefully handle these unused slots? IF not what is the correct method for properly removing widgets from memory.

Thanks in Advance!

GC is not collected immediately, it’s take a bit of time like 60 sec by default if my memory is good.

After, for and UObject need to be collected by GC, you need to have 0 reference to it, so be sure you don’t store any pointer to you’r widget somewhere.

You can Collect Garbage manually:

Providing the widgets are dereferenced and not parented by anything, it will scoop them up immediately.

Yup it cleans itself up after 60 seconds like you said. I tested by making 1000+ instances of the slots by quickly opening and closing the inventory menu and then waited - and after 60 secs there was only the current 16 for the menu in the instance drop down menu in the editor.