Clarification about GC and NewObject<>
I have a plugin module where the implementation class is derived from custom derivation of IModuleInterface. The module loads fine and is accessible. Inside the module implementation I have a private regular C++ pointer (not decorated with UPROPERTY because after all this class is a module class and not an UObject) to a custom UObject. Inside StartupModule I allocate an instance of that object using NewObject<>.
Is this sufficient for keeping said private UObject alive? NewObject<> assigns a default Outer object, no? And so isn't that good enough to keep it alive from the GC? I test the persistence by calling GetWorld()->ForceGarbageCollection(true) inside my custom PlayerController in the main game module repeatedly through a triggered UFUNCTION, and the UObject in question seems to stay accessible. I am just getting lucky or is what I am doing legit?
As I understand things that shouldn't be safe, I didn't think that the outer contributed to reference counting by default. So I'm surprised it's working. Anyway, to be safe, just call
answered Apr 15 '15 at 06:48 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here