Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How to dynamically allocate memory, self memory management



How to dynamically allocate memory for UE4 container i.e TArray, and UCLASS, and USTRUCT? without troubling GC and allow me to manage my own memory.

Where is the best location of free those memory, I am currently override the BeginDestroy();

PS: USTRUCT seems can work with new.

MY intention:

I am making a inventory system, so I build a UCLASS() APlayerInventory from AActor.

Since UPROPERTY does not allow TArray* and FStruct*, and my inventory will contain tons of information. So I am considering using pointers and running my own dynamic allocated memory.

Therefore, I use transitional c++ approach new in constructor, and no compile error and editor crash. I predicatively know it wont work TT

     Inventory = new APlayerInventory();

     // dynamically allocated a TArray to store our inventory info
     InventoryItemInfos = new TArray<FInteractableItemInfo*>();

where FInteractableItemInfo is USTRUCT, that i will use to pass infomation between player controller and UI

Here are the crash reporter message:

Fatal error: [File:D:\Build\++UE4+Release-4.15+Compile\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 2538] UObject() constructor called but it's not the object that's currently being constructed with NewObject. Maybe you trying to construct it on the stack which is not supported.

UE4Editor_MannequinVsMaximo_852!APlayerInventory::APlayerInventory() [e:\unreal4\unreal project\mannequinvsmaximo\source\mannequinvsmaximo\playerinventory.cpp:10] UE4Editor_MannequinVsMaximo_852!APlayableCharacter::APlayableCharacter() [e:\unreal4\unreal project\mannequinvsmaximo\source\mannequinvsmaximo\playablecharacter.cpp:35] UE4Editor_MannequinVsMaximo_852!InternalConstructor()

FINAL PS: If anyone knows how to detect memory leak, please enlighten me. I am planing to make some memory trace function.


THANKS IN ADVANCED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Product Version: UE 4.15
more ▼

asked Jun 21 '17 at 02:00 AM in C++ Programming

avatar image

18 2 3 6

avatar image ShankIsUsed Jun 21 '17 at 02:28 AM


I use

     Inventory = NewObject<APlayerInventory>(this);

instead. and Get other error message from crash reporter. Fatal error: [File:D:\Build\++UE4+Release-4.15+Compile\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 3301] NewObject with empty name can't be used to create default subobjects (inside of UObject derived class constructor) as it produces inconsistent object names. Use ObjectInitializer.CreateDefaultSuobject<> instead.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Anytime you use UCLASS, USTRUCT, UENUM, it is going to be a part of UE4's memory management system as that is what these macros will do.

As for managing your own memory, I would suggest not using any UE4 macro as I am still not 100% on what each will do, only that they are setup for memory management. If you create a class that doesn't extend anything from UE4, such as UObject, you are then probably expected to manage any memory reserved for those types.

It is kind of an odd thing to try and manage in the game frame work because memory management is very much a part of it and meant to be used.

more ▼

answered Jun 23 '17 at 02:58 AM

avatar image

461 13 11 26

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question