I thought writing DynamicObject*test = new DynamicObject would put the refCount to 1 but it is == 0.
I truely don't understand the mechanism behind this, who destructs "test" if I do not manually delete it ? Ok it will if I do put it into a var, but if I just create a DynamicObject like above (sure it's useless) would it then leak ?
Ok got it but what about just writing DynamicObject*test = new DynamicObject; alone
would it leak or not ? In my understanding, yes because it is not held into any reference-counted container and therefore will never be incremented to 1 to then come back to 0 and being deleted. Otherwise I truely do not understand how it does work under the hood.
I'm used with objective-c where any new object (or copy) will comes with a refCount == 1 (vs 0 in this case)
Yes, of course that'd leak because there's no smart-pointer to delete it when it goes out of scope. DynamicObject::Ptr p = new DynamicObject() would be safe though. Unlike obj-C the objects start with refcount = 0 because it'll be automatically incremented to 1 when it first gets added to a container.