Memory Management (new vs malloc)

Coming from a background of Java and C# back to C++, I’ve been pretty curious about Unreal’s memory management. While looking around the web at how people choose to delete actors, i found a couple poor souls that used the delete operator instead of Unreal’s cleanup method. The consensus was they shouldn’t be doing that and they should just let Unreal do everything for them…which seemed reasonable but i was still curious about what happens when implementing your own memory management at that low level.

https://wiki.unrealengine.com/Garbage_Collection_%26_Dynamic_Memory_Allocation#Destroying_.2F_Deallocating

It looks to me like you’ll need to use the ‘delete’ operator for every ‘new’ to manage your allocations on the ‘Free Store’.

Or…if you really don’t like having a full head of hair…you can go the C route and use malloc/free from the Dark ages before Object Oriented programming. I’ve only been programming about 5 years, but I never want to go back to this.

I’m curious if anyone has used their own Memory Management in Unreal or plans to and why?

I plan to use Unreal Memory management for several reasons.

  1. I’m more interested in game mecanics than low level programming (we may argue that’s no good reason to do bad code)
  2. I trust Unreal to do a decent job at handling memory, provided I use it correctly.
  3. I want to master Game design and Game Mecanics before I tackle this kind of improvement.

Regarding the page you linked, I see they use ConditionalBeginDestroy() After the Destroy() method. I’m curious about why this would be required. I don’t think it could apply on the Projectile since we use Destroy() the the object itself anyway.

You shouldn’t be using new/delete in modern C++. You should be using smart pointers instead.

RAII at its heart.

Privacy & Terms