to control it like you want, you need to use shared pointers: Shared Pointers | Unreal Engine Documentation
TSharedPtr OtherNodeRef = Node; - add reference to node
when OtherNodeRef goes out of scope, node will lose 1 reference.
> UObject * obj = NewObject(this, UClassOfPlayer); //What is the reference count here?
1
> SomeActor.SomeFunction(obj);//SomeActor may use obj for long time
> obj->ConditionalBeginDestroy(); //I don't need obj anymore, but what if SomeActor still needs obj which was passed to it as a parameter
Too bad for SomeActor, ConditionalBeginDestroy will destroy it, and Some Actor will have a dead object.
FPlatformProcess::Sleep(time);
objectParameter->SomeFunction(); //if another method don't need objectParameter anymore and called ConditionalBeginDestroy on this object I will be screwed.
//How to tell garbage collector that I need objectParameter's object until that point?
//how can I tell garbage collector that I don't need objectParameter's object after that point?
if you do not mess around with ConditionalBeginDestroy then you just add references as shared pointers. When you do not need a reference any longer you null it. When there are no more references left, object will be garbage collected. ConditionalBeginDestroy is asynchronous operation. So, you don’t know when exactly it will be destroyed, but it will be sooner than later.