Skip to content

Commit

Permalink
fix leak issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mmin18 committed Aug 25, 2012
1 parent 29d0229 commit 6b08c07
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 0 additions & 4 deletions README.md
Expand Up @@ -8,7 +8,3 @@ The patch is a zip file contains patch.lua and other lua codes. The sample code
The sample iOS project loads the patch from a url (which you probably want to change in AppDelegate.m) before launch.

The Original.png and Patched.png shows the difference.
### Issue
The mutated version of wax leaks when call method directly from Obj-C!!!

The issue is located at wax_instance.m, TODO mark.
3 changes: 3 additions & 0 deletions WaxPatch/WaxPatch/wax/wax_gc.m
Expand Up @@ -46,6 +46,9 @@ + (void)cleanupUnusedObject {
lua_pushvalue(L, -1);
lua_pushnil(L);
lua_rawset(L, -4); // Clear it!
if(instanceUserdata->waxRetain) {
[instanceUserdata->instance release];
}
}
}

Expand Down
1 change: 1 addition & 0 deletions WaxPatch/WaxPatch/wax/wax_instance.h
Expand Up @@ -20,6 +20,7 @@ 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.
BOOL waxRetain; // retained by wax, release instance when wax_gc
} wax_instance_userdata;

int luaopen_wax_instance(lua_State *L);
Expand Down
6 changes: 4 additions & 2 deletions WaxPatch/WaxPatch/wax/wax_instance.m
Expand Up @@ -218,8 +218,10 @@ 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
// cause a obj-c leak, should we release it later?
wax_instance_create(L, self, NO);
// to avoid obj-c leak, we release instance when wax_gc
wax_instance_userdata *data = wax_instance_create(L, self, NO);
data->waxRetain = YES;
// [self release];
// END_STACK_MODIFY(L, 0)
// return NO; // userdata doesn't exist
}
Expand Down

0 comments on commit 6b08c07

Please sign in to comment.