why is TArray.Init(MyClass) calling the Deconstructor of MyClass?
I want to use a TArray to store data of a particular class, but when I use TArray.init, I notice that after it's done initializing my class, the deconstructor is called. Is there a way around this?
This is a simplified version of what my program is storing, but the basics are all there.
I've tried using TArray.Add and TArray.SetNum, but for some reason the deconstructor is always called. Is there a way around this?
asked Jul 07 '19 at 05:11 AM in C++ Programming
Instead you can use
If nothing else works, or you must construct the object for any reason, you can use
All of that said, and I don't know your specific use case, but how much does it matter? Most of the time, destructors are cheap and in the majority of cases it's negligible. Unless you have a strong reason to believe it's impacting your performance in a meaningful way, it's probably not worth the worry.
answered Jul 07 '19 at 06:35 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here