Added a way for love's reference-counted objects to be released more safely in some situations (e.g. setters)

This commit is contained in:
Alex Szpakowski
2013-06-09 02:42:33 -03:00
parent f253a016f6
commit 35984790e5
4 changed files with 31 additions and 5 deletions
+27
View File
@@ -65,6 +65,33 @@ public:
**/
virtual void release();
/**
* Meant to be used as a temporary object. Facilitates safer and cleaner
* code to release objects by doing so when the AutoRelease object is
* destroyed (e.g. goes out of scope.)
**/
class AutoRelease
{
public:
AutoRelease(Object *obj)
: object(obj)
{
}
~AutoRelease()
{
if (object)
object->release();
}
private:
AutoRelease() {}
Object *object;
}; // AutoRelease
private:
// The reference count.