C++ static data clean up?

class PROJECTTAP_API BlockingTileManager
static std::vector<ABlockingTile*> activatedBlocks;
const static unsigned char size_limit{ 3 };
static void AddTile(ABlockingTile* tile);

so I have the code above. The problem is like this: I launch the editor from vs2013 and play the game inside the editor, then do something to cause 3 ABlockingTile pointers to be added to the activatedBlocks collection;

but then I end the game inside the editor, start it again, those pointers which were added last time were still there, but the actual data on the heap was gone (duh)

Tried to clean up in the destructor, but the destructor was never called


Hey there! You should get rid of the destructor, derive your class from UObject and turn it into a UCLASS instead. Then, instance your objects via NewObject and let Unreal’s garbage collector take care of it for you.

I see that you’re using a couple of standard C++ things such as std::vector. I would suggest using the managed UE4 equivalents instead (TArray, FVector, etc) since they can be considered for GC.

That is very helpful comment.

Just wondering, since I don’t really need this class to be a Uobject.

Just some cases, if I can handle memory allocation efficiently myself, should I customize the class and dont make it UObject?

I would honestly still make it a UObject. There’s no real downside to it - it doesn’t affect performance, allows much easier engine integration, etc - hell, it’s the recommended way of doing it :stuck_out_tongue: using the “new” keyword makes the compiler complain :stuck_out_tongue:

A static cleanup function called from my gamemode destructor works well for me. Even if you follow Jargon’s advice with the UObject its nice to cleanup pointers.