new coral::PropertyManager
allocates a new PropertyManager on the heap, but because it is a temporary variable you will never release it. This is the standard Java idiom, since Java is a garbage-collected language where the GC will take care of releasing this dangling reference for you.
If you want to use new
here for some reason, the proper way to do this would be as follows:
auto *pm = new coral::PropertyManager; // auto is C++11 syntax
m_propertyManager(pm);
delete pm; // when you're done using it
Your second option is correct, in that it allocates Mgr
as an automatic variable on the stack, which will be released when the function exits. m_propertyManager(&Mgr);
passes the address of Mgr to the function, which will allow it to modify the Mgr object (although this is probably better done by passing Mgr as a reference).
Just note that if m_propertyManager is an object that persists after the current scope exits, and if it stores the reference to Mgr somewhere, then when you exit the current scope and the Mgr object is destroyed you will find m_propertyManager holding a reference to invalid memory.