If use FMemory::Malloc, how to invoke consturctor with parameters?

how to invoke consturctor with parameters by FMemory::Malloc?
In my project, program would crash when invoke delete in AHGameMode::Tick(float DeltaSeconds) function, so isn’t UE4 support to use C++ operator new and delete in Tick() function?
if so I want to test FMemory::Malloc instead of C++ operator new, but I don’t know how to invoke constructor by FMemory::Malloc.

following is the exception stack:


UE4Editor_Core!rml::internal::Block::freePublicObject()
UE4Editor_Core!rml::internal::ExtMemoryPool::initTLS()
UE4Editor_Core!FMallocTBB::Free() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\core\private\hal\malloctbb.cpp:115]
UE4Editor_Core!FMemory::Free() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\core\public\hal\fmemory.inl:49]
UE4Editor_MyProject_784_Win64_DebugGame!operator delete]() [d:\workspace\unreal_project\huaikongxin2\program\client\huaikxcli\source\huaikx\huaikx.cpp:15]
UE4Editor_MyProject_784_Win64_DebugGame!HServices::HRecvMsg::~HRecvMsg() [d:\workspace\unreal_project\huaikongxin2\program\client\huaikxcli\source\huaikx\services
etwork\hrecvmsg.cpp:33]
UE4Editor_MyProject_784_Win64_DebugGame!AHGameMode::Tick() [d:\workspace\unreal_project\huaikongxin2\program\client\huaikxcli\source\huaikx\graphics\world\hgamemode.cpp:121]
UE4Editor_Engine!AActor::TickActor() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private\actor.cpp:814]
UE4Editor_Engine!FActorTickFunction::ExecuteTick() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private\actor.cpp:111]
UE4Editor_Engine!FTickFunctionTask::DoTask() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private	icktaskmanager.cpp:262]
UE4Editor_Engine!TGraphTask<FTickFunctionTask>::ExecuteTask() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\core\public\async	askgraphinterfaces.h:999]
UE4Editor_Core!FNamedTaskThread::ProcessTasksNamedThread() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\core\private\async	askgraph.cpp:932]
UE4Editor_Core!FNamedTaskThread::ProcessTasksUntilQuit() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\core\private\async	askgraph.cpp:679]
UE4Editor_Core!FTaskGraphImplementation::WaitUntilTasksComplete() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\core\private\async	askgraph.cpp:1776]
UE4Editor_Engine!FTickTaskSequencer::ReleaseTickGroup() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private	icktaskmanager.cpp:530]
UE4Editor_Engine!FTickTaskManager::RunTickGroup() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private	icktaskmanager.cpp:1435]
UE4Editor_Engine!UWorld::RunTickGroup() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:704]
UE4Editor_Engine!UWorld::Tick() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\engine\private\leveltick.cpp:1197]
UE4Editor_UnrealEd!UEditorEngine::Tick() [d:\build\++ue4+release-4.12+compile\sync\engine\source\editor\unrealed\private\editorengine.cpp:1349]
UE4Editor_UnrealEd!UUnrealEdEngine::Tick() [d:\build\++ue4+release-4.12+compile\sync\engine\source\editor\unrealed\private\unrealedengine.cpp:368]
UE4Editor!FEngineLoop::Tick() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:2774]
UE4Editor!GuardedMain() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\launch\private\launch.cpp:148]
UE4Editor!GuardedMainWrapper() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\build\++ue4+release-4.12+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:200]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:264]
kernel32
ntdll

I guess that one is like the C malloc. That means you really REALLY shouldnt use it on classes. Malloc doesnt call constructors and all the default values are undefined, so they could be 0 or a random number, wich is very problematic.
Normally, one uses “new” to create new C++ classes, you are on C++, not C, and new is normally better in every way possible, even the c++ creator says that you should never ever use malloc, and only use new and delete in very controlled ways.
Also, you actually shouldnt use either new/delete or malloc when working with UE4, unless you are interfacing with a external library or doing code that doesnt interface with the engine becouse they are normal c++ classes and the like . If you use UOBJECT, just create them the normal way so they are properly registered in the engine systems, this way.

thx so much for help!
I found that even use FMemory::Malloc() instead of **C++ operator new **, this issue also reproduced again.
I check my code very carefully and found that there’s a memory addressability issue, it caused crash. thx all the same, have a nice day!

My personal recomendation its that you use Epic games systems for managed memory. Its very simple, just have your class be an UObject, and when you save its pointer on a “parent” or whatever class, use UPROPERTY() on that pointer. That way, Epic code knows to keep that one in mind, and once its not referenced by anything, it will automatically be deleted. Also check C++11 smart pointers like unique_ptr and shared_ptr. This days, good C++ code tries to avoid “naked” new and delete all thats possible.

ok, your suggestions are very useful!

UE has it’s own smart pointer suite as well, see TSharedPtr, Makeshareable etc.