General questions: Dispose() and impicit convertions

Tubulii

13-08-2012 12:47:17

I am using mogre for quite some time, but there is still a not I do not know.
This recent topic made me thing about myself and how I am using mogre. As far as I know, there a some rules about resource handling.
So my question is:
In which cases do I have to care about the wrapper handles and implicit conversions in order to avoid errors (like in the mentioned in the topic above)?
I will write down, what I know...

Resource ptrs (e.g. MaterialPtr, TexturePtr, MeshPtr)
Always dispose (the wrapper) with .Dispose (e.g. by using a 'using' statement), even if you still want to keep the resource.
Implicit convertions (between ptrs) are (or could be) dangerous, FromResourcePtr(...) is a safe alternative.
Get the object by 'Target' (as an alternative to an implicit convertion).

Are there any other classes which are some how 'dangerous'? And need special care?

Thanks

zarfius

14-08-2012 12:35:31

As far as I know any class that implements the IDisposable interface needs such care and also, any new class that have properties or fields that are disposable themselves also need to implement IDisposable.

It really depends on how the disposable pattern has been implemented. I think, if the correct implementation has been used the Dispose method will always be called in the classes finaliser if the programmer forgets to call it themselves, however, this has a performance impact in the garbage collector. There are lots of articles around implementing the disposable pattern correctly. Here's a couple:

I just found this answer on stack overflow and it explains it better than I ever could.
http://stackoverflow.com/questions/5740 ... 659#574659

Here's Microsoft's official documentation
http://msdn.microsoft.com/en-us/library ... sable.aspx

And another.
http://dixond.blogspot.com.au/2010/08/e ... -know.html

Tubulii

14-08-2012 13:12:01

Thanks for your answer. I've read the articles and I found this. Its a reeealy long article about resource management in .Net. Although I've already read similar articles about this topic, its still interesting.
And maybe we should add a note to the wiki (and/or to the tutorials?) about the resource ptrs, otherwise these informations get lost in the forum...