Hi,
I haven’t developed in C++ in years! I’ve been working in ActionScript3, JavaScript, Java, C# all these years…
All my pass knowledge is managed code with no need to worry about pointers and releasing memory…
I’ve heard that the new C++ (I think it’s version 11) it has something called smart pointers, that it’s like managed code… no need to release memory.
Am I getting it right? Is the new Engine works like that?
Any information about this subject would be great!
The fact that it has garbage collection does not mean that that it is automatic.
At it’s core it is C++ and in C++ RAII (aka smart pointers) is not the default way the memory is managed unless you explicitly allocate memory as smart point i.e
/*C++11 code*/
#include <memory>
int main(){
int * p = new int[10]; //memory leak
std::shared_ptr<int> p1 = std::shared_ptr<int>(new int[10]); //no leak
return 0;
}
So you cannot assume that there is automatic garbage collection in C++, unless you allocate it as a RAII object.
UObjects, our main reflection based class system, is garbage collected at a specified interval (typically 30 sec, but configurable)
**FWeakObjectPtr **is a pointer to a UObject that won’t affect garbage collection and will be NULL’d if it is in fact GC’d TSharedPtr<> and TSharedRef<> are ref counted shared pointers as you’d expect them, and will free memory when all references are removed
TSharedRef<> is basically a TSharedPtr<> that cannot be NULL
**TWeakPtr **works with TSharedPtr<> and doesn’t hold a ref count
Finally you have regular old pointers that you manage the memory lifetime itself. There is lots of documentation available and in the code on these class types. Hope this helps.
We are working on identifying and adopting the main C++11 extensions and you’ll already find many examples in the code base. We have to keep in mind many different compilers, so we have typically adopted the features that are most compatible across all compilers.