mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Added Object:release. Calling it is the equivalent of removing all Lua-side references to an object and doing a full garbage collection cycle (thus deleting the object from memory if nothing else in LÖVE's code is referencing it).
Any attempt to call a method on the object after it has been released will result in an error. Object:release() returns true if it was successful, or false if not (if it has already been released previously). --HG-- branch : minor
This commit is contained in:
@@ -85,7 +85,8 @@ Variant::Variant(love::Type udatatype, void *userdata)
|
||||
{
|
||||
Proxy *p = (Proxy *) userdata;
|
||||
data.userdata = p->object;
|
||||
p->object->retain();
|
||||
if (p->object)
|
||||
p->object->retain();
|
||||
}
|
||||
else
|
||||
data.userdata = userdata;
|
||||
@@ -105,7 +106,7 @@ Variant::Variant(const Variant &v)
|
||||
{
|
||||
if (type == STRING)
|
||||
data.string->retain();
|
||||
else if (type == FUSERDATA)
|
||||
else if (type == FUSERDATA && data.userdata != nullptr)
|
||||
((love::Object *) data.userdata)->retain();
|
||||
else if (type == TABLE)
|
||||
data.table->retain();
|
||||
@@ -127,7 +128,8 @@ Variant::~Variant()
|
||||
data.string->release();
|
||||
break;
|
||||
case FUSERDATA:
|
||||
((love::Object *) data.userdata)->release();
|
||||
if (data.userdata != nullptr)
|
||||
((love::Object *) data.userdata)->release();
|
||||
break;
|
||||
case TABLE:
|
||||
data.table->release();
|
||||
@@ -141,14 +143,14 @@ Variant &Variant::operator = (const Variant &v)
|
||||
{
|
||||
if (v.type == STRING)
|
||||
v.data.string->retain();
|
||||
else if (v.type == FUSERDATA)
|
||||
else if (v.type == FUSERDATA && v.data.userdata != nullptr)
|
||||
((love::Object *) v.data.userdata)->retain();
|
||||
else if (v.type == TABLE)
|
||||
v.data.table->retain();
|
||||
|
||||
if (type == STRING)
|
||||
data.string->release();
|
||||
else if (type == FUSERDATA)
|
||||
else if (type == FUSERDATA && v.data.userdata != nullptr)
|
||||
((love::Object *) v.data.userdata)->release();
|
||||
else if (type == TABLE)
|
||||
data.table->release();
|
||||
|
||||
Reference in New Issue
Block a user