Closed Cazadorro closed 5 years ago
Everything is destroyed when the DeviceManager goes out of scope, but the individual things don't before then (except for SharedPtrs and SharedFutures and such, since they're standard smart pointers). For instance, with that example if source.destroy()
wasn't called and it looped to play multiple files, it would leak multiple sources prior to the end since there's no way to get back the previously allocated ones.
The more general reason for the lack of RAII is because it's possible for destruction to fail (or even crash) if done incorrectly since devices own contexts, and contexts own sources/buffers/etc. If they're destructed in the wrong order, it will crash since they're effectively pointers to those resources that have been deleted (and I'm not fond of the idea of resources keeping their owners alive after the app has gotten rid of the latter). There is an AutoObj
wrapper container that adds RAII behavior for most resources, although the app has to promise it will scope them correctly when using it or else.
Thanks for the detailed reply!
Many of the examples include statements like
ctx.destroy()
ordev.close()
whilenew
is no where to be found, and destruction is being called at the end of scope. Is there a particular reason for this pattern? It appears as if all the objects actually have destructors any way.