Help please! I need to deallocate memory using delete[], but I get an Access Violation crash

I’ve browsed through the forums, and I understand there’s rarely (if at all) a need to use new and delete keywords within UE. However, I’m trying to do something very uncommon and would appreciate any help / tips in this scenario:

I need to call a dll function that takes in several float pointers (all declared and set to nullptr within my code).

The dll function allocates memory to those passed pointers (using new[]) and then assigns their value.

When the function returns, the passed pointers are now populated with values, I use those values (floats) and assign them to my class variables.

At the end of that, I need to call delete[] on the pointers that were passed to and allocated by the dll.
All of this happens within a single local scope - one of my class’ function.

When i call delete[] I get an Access Violation crash.

Since the dll explicitly requires non-const float*&, I need to use raw pointers and call delete on those at some point. The dll is a generic, third-party dll that is independent from UE, and i’ve used the approach below with the same dll in other software (not UE) and works as expected.

Here’s some pseudo code:

float* floatArr = nullptr;


myFloatMemberVar = floatArr[0];

delete[] floatArr;

I’ve read unreal has it’s own implementation of the delete, which I believe is what is getting in the way.

Any help or pointers (pun-intended) would be greatly appreciated!!

Try with free(floatArr) instead of delete[].

Is the DLL a publicly available library? Can you share the actual DLL call you are making? (That’s a very odd API to require you to use delete[] like that.)

Thank you! That solved the crash and the memory leaks :raised_hands:

Yeah, I agree with you about the oddness. But no, it’s a private dll made by another team we work with.