Because people are already speculating about my sudden death
, here is a short new blog entry. :) (There'll be a more interesting one tomorrow, I hope)
A frequently asked question I've received several times by mail now: Using irrklang
's reference counted objects, when do I have to use drop()
and when not?
The answer is very easy: Just as in Irrlicht
, you only need to call drop() to an object if you received it by calling a method starting with 'create' or when creating it yourself via the C++ 'new'.
After you don't need the object anymore, just call drop() to let the reference counter handle the object descruction automaticly. There is one little single exception to this rule in irrKlang: If you recieved a pointer to an ISound
interface, you always have to call drop() after you don't need it any more. Why?
ISound objects are the only public objects which are pushed and used between multiple threads, and you can never know if another thread already has deleted it in between. That's why ISound is also derived from IVirtualUnknown
instead of IUnknown
So maybe a more future prove rule would be: If you get a pointer to an object derived from IVirtualObject, always call drop() if you don't need it anymore. But don't despair: If you are still unsure, just don't call drop() temporarily. Nothing really bad will happen then, you will only waste some small amount of memory used for storing some file names and positions etc.
IrrKlang will still free huge and critical system resources itself in this situation automaticly behind the scenes. Going to add this to the FAQ soon.