Almost-constant crashing on UObjectBaseUtility::GetOutermost() due to UMG

Around 8 out of 10 times when I have activated something that puts UMG widgets on screen, when I quit the game and whether or not I remove those widgets before doing so, the game breaks in VS in this function:

UPackage* UObjectBaseUtility::GetOutermost() const
{
	UObject* Top = (UObject*)this;
	for (;;)
	{
		UObject* CurrentOuter = Top->GetOuter(); // This line
		if (!CurrentOuter)
		{
			return CastChecked<UPackage>(Top);
		}
		Top = CurrentOuter;
	}
}

Is there any specific way I’m supposed to be handling/cleaning up widgets? What I do over the course of the game is spawn instances onto the screen and store them in a TMap, and then remove them from the viewport and call delete on them (also emptying the TMap).

Edit: Don’t know why I never did this before but I removed the line that deleted the widgets from memory. Now it never crashes. However, this worries me because I’m constantly emptying the TMap and refilling it with new widgets. The pointers to old widgets are just lost this way. Isn’t this a memory leak?