Sha256: 473f626e7e53ac839f4144b69df1d43751a02e4d82bb5b41c1d6e5ee5c240e2c

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

//
//  wax_garbage_collection.m
//  WaxTests
//
//  Created by Corey Johnson on 2/23/10.
//  Copyright 2010 Probably Interactive. All rights reserved.
//

#import "wax_gc.h"

#import "lua.h"
#import "lauxlib.h"

#import "wax.h"
#import "wax_instance.h"
#import "wax_helpers.h"

#define WAX_GC_TIMEOUT 1

@implementation wax_gc

static NSTimer* timer = nil;

+ (void)start {
    [timer invalidate];
    timer = [NSTimer scheduledTimerWithTimeInterval:WAX_GC_TIMEOUT target:self selector:@selector(cleanupUnusedObject) userInfo:nil repeats:YES];
}

+ (void)stop {
    [timer invalidate];
    timer = nil;
}

+ (void)cleanupUnusedObject {   
    lua_State *L = wax_currentLuaState();
    BEGIN_STACK_MODIFY(L)
    
    wax_instance_pushStrongUserdataTable(L);

    lua_pushnil(L);  // first key
    while (lua_next(L, -2)) {
        wax_instance_userdata *instanceUserdata = (wax_instance_userdata *)luaL_checkudata(L, -1, WAX_INSTANCE_METATABLE_NAME);
        lua_pop(L, 1); // pops the value, keeps the key
            
        if (!instanceUserdata->isClass && !instanceUserdata->isSuper && [instanceUserdata->instance retainCount] <= 1) {
            lua_pushvalue(L, -1);
            lua_pushnil(L);
            lua_rawset(L, -4); // Clear it!
        }        
    }

        
    END_STACK_MODIFY(L, 0);
}

@end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
candle-0.0.7 lib/candle/generators/lua/wax/lib/wax_gc.m
candle-0.0.6 lib/candle/generators/lua/wax/lib/wax_gc.m
candle-0.0.4 lib/candle/generators/lua/wax/lib/wax_gc.m
candle-0.0.3 lib/candle/generators/lua/wax/lib/wax_gc.m
candle-0.0.2 lib/candle/generators/lua/wax/lib/wax_gc.m
candle-0.0.1 lib/candle/generators/lua/wax/lib/wax_gc.m