The best of ref_ptr is that you don't have to explicitly delete the object.
It will be deleted automagically when the ref_ptr goes out of scope:
{
osg::ref_ptr<MyClass> object1 = new MyClass();
...
} <-- object1 is deleted, destructor called, etc.
If you really need to delete the object before that point (and this is not
very common) you must do:
object1 = NULL;
Again the destructor will be called, and the memory will be deleted.
Calling a function of a deleted object will not crash until the function
tries to access a member variable.
-----Mensaje original-----
De: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] En nombre de Oliver Kutter
Enviado el: viernes, 06 de octubre de 2006 14:24
Para: osg users
Asunto: [osg-users] These ref pointer things
Hi,
I have a question about the osg::ref_ptr things. What is the difference
between those two variants (MyClass inherits from the class Referenced):
1:
osg::ref_ptr<MyClass> object1 = new MyClass();
object1.release();
2:
MyClass* object2 = new MyClass();
delete object2;
I have found out, that the 2nd variant deletes the object by calling the
destructor. But what about the first variant. Here the destructor is not
called. Is the object really deleted?
I have some parts in my code, where I call methods from deleted objects,
but nothing happens. Normally the call of these methods should crash the
application, because the object is deleted.
regards,
Oliver
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/