Memory broken on Object destruction

I’m currently trying to implement a Queue in C++ that I can use from Blueprint.
Problem is, that every time the queue gets destructed, the pointers to the queue elements are broken.

Queue construction:

Queue destruction:


Element Types:

The pointer to head and tail should not get garbage collected as long as the queue references them. Calling functions on the queue works without problems. Only when destructing the queue everything goes boom. Pretty lost here.

To fix it, i created

void EnsureTailExists()
    if (!tail)
        head = tail = NewObject<UQueueBPElementTail>();

and call it in all functions that need the tail to exist.

and to clear it:

void UQueueBP::BeginDestroy()

void UQueueBP::Clear()
	// If there is no tail, we never had elements.
	if (!tail)

    ForEachElement([this](UQueueBPElement*& currentElement) -> void
        // We are going to delete the element and thus break the loop.
        // To prevent this we need to set the pointer back one element.
        UQueueBPElement* previousElement = currentElement->previous;
        currentElement = previousElement;
    ensure(numElements == 0);
    ensure(head == tail);
    ensure(tail->previous == nullptr);
    ensure(tail->next == nullptr);
    ensure(tail->GetClass() == UQueueBPElementTail::StaticClass());