Skip to content

Commit

Permalink
fix gc issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Tu Yimin committed Mar 19, 2013
1 parent 6b08c07 commit cc19142
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions WaxPatch/WaxPatch/wax/wax_gc.m
Expand Up @@ -48,6 +48,10 @@ + (void)cleanupUnusedObject {
lua_rawset(L, -4); // Clear it!
if(instanceUserdata->waxRetain) {
[instanceUserdata->instance release];
<<<<<<< HEAD
=======
instanceUserdata->waxRetain = NO; // fix gc bad exec
>>>>>>> fix gc issue
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions WaxPatch/WaxPatch/wax/wax_instance.h
Expand Up @@ -20,7 +20,11 @@ typedef struct _wax_instance_userdata {
BOOL isClass;
Class isSuper; // isSuper not only stores whether the class is a super, but it also contains the value of the next superClass.
BOOL actAsSuper; // It only acts like a super once, when it is called for the first time.
<<<<<<< HEAD
BOOL waxRetain; // retained by wax, release instance when wax_gc
=======
BOOL waxRetain; // TODO: need release instance when gc
>>>>>>> fix gc issue
} wax_instance_userdata;

int luaopen_wax_instance(lua_State *L);
Expand Down
6 changes: 6 additions & 0 deletions WaxPatch/WaxPatch/wax/wax_instance.m
Expand Up @@ -81,6 +81,7 @@ int luaopen_wax_instance(lua_State *L) {
instanceUserdata->isClass = isClass;
instanceUserdata->isSuper = nil;
instanceUserdata->actAsSuper = NO;
instanceUserdata->waxRetain = NO;

if (!isClass) {
//wax_log(LOG_GC, @"Retaining %@ for %@(%p -> %p)", isClass ? @"class" : @"instance", [instance class], instance, instanceUserdata);
Expand Down Expand Up @@ -129,6 +130,7 @@ int luaopen_wax_instance(lua_State *L) {
superInstanceUserdata->instance = instanceUserdata->instance;
superInstanceUserdata->isClass = instanceUserdata->isClass;
superInstanceUserdata->actAsSuper = YES;
superInstanceUserdata->waxRetain = NO;

// isSuper not only stores whether the class is a super, but it also contains the value of the next superClass
if (instanceUserdata->isSuper) {
Expand Down Expand Up @@ -218,7 +220,11 @@ BOOL wax_instance_pushFunction(lua_State *L, id self, SEL selector) {
if (lua_isnil(L, -1)) {
// TODO:
// quick and dirty solution to let obj-c call directly into lua
<<<<<<< HEAD
// to avoid obj-c leak, we release instance when wax_gc
=======
// cause a obj-c leak, should we release it later?
>>>>>>> fix gc issue
wax_instance_userdata *data = wax_instance_create(L, self, NO);
data->waxRetain = YES;
// [self release];
Expand Down

0 comments on commit cc19142

Please sign in to comment.