My TArray<> keeps running out of memory?

Ok so I’ve got an array of my custom class AMech_RPGCharacter:

TArray<AMech_RPGCharacter*> members;

It appears to run out of memory sometimes when I use Num() to check if there’s anything in it.

Like so:

UGroup* group = GetOwner()->GetGroup();

// Does the owner have a group and is there more than 1 other person
if (group != NULL && group->GetMembers().Num() > 1) {}

I’m doing this in a few places along with lopping through the array several times every Tick() without issue.

What would cause “Ran out of memory allocating 18446744069128253160 bytes with alignment 0”.

I only add to the array once the game begins and never do a Remove() or Add() after that?

**Full source code: Mech_RPG/Mech_RPG at master · belven/Mech_RPG · GitHub **

I would not answer for your question, because I don’t have time to debug your code;) but I’ll give you advice.

This for example:

TArray<AMech_RPGCharacter*> members = *new TArray<AMech_RPGCharacter*>();

Does it even compile?

Should be replaced with:

UPROPERTY(/*any of the specifiers: Transient/EditDefaultsOnly etc*/)
TArray<AMech_RPGCharacter*> members;

without UPROPERTY your members probably would be cleaned by GC.

Read this:

TArray | Unreal Engine Documentation - official documentation.

Or this

A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums - wiki by .

Thats really wierd behavior, it only happens when you use Num()?

It looks like this might have something to do with it?

TArray<AMech_RPGCharacter*> UGroup::GetMembers() {
	return members;
}

Is that the wrong way to do a Get for TArray?

It causes this:

	TArray(const TArray& Other)
	{
		CopyToEmpty(Other);
	}

leading to being out of memory?

It appears to happen after a certain time and when I try to do something with GetMembers().

Can TArray members; ever be NULL?

Ok so, the GetMembers() was the issue.

When returning a TArray<> make sue to passit as a reference:

TArray& GetMemebers();