bang590 / JSPatch

JSPatch bridge Objective-C and Javascript using the Objective-C runtime. You can call any Objective-C class and method in JavaScript by just including a small engine. JSPatch is generally used to hotfix iOS App.
MIT License
11.36k stars 2.24k forks source link

老项目MRC dealloc时会出现crash,JSPatch是否无法兼容MRC #212

Open gbfansheng opened 8 years ago

gbfansheng commented 8 years ago

使用JSPatch替换一个类中的方法,并传递参数到JS,完成执行后,手动release后调用dealloc造成crash,找不到crash log。

lilidan commented 8 years ago

同求

bang590 commented 8 years ago

贴下代码?手动release是怎样release

gbfansheng commented 8 years ago

问题说明: 尝试使用JSPatch修改LoginView的初始化方法,LoginView的Controller释放的时机是在接收到网络请求后执行。个人认为是由于JSPatch持有了传入的参数的引用还没释放时Controller就进行释放,造成崩溃,而且没有Log。但是不知道怎么解决,因为无法控制GC的时间。当我把LoginView的[super dealloc]注释后就不会发生崩溃。

Controller:(Controller会在收到网路请求后release)

- (void)dealloc
{
    [_loginView release], _manualLoginView = nil;
    [super dealloc];
}

LoginView:

- (void)dealloc
{
    [_cellNumTextField release], _cellNumTextField = nil;
    [_regInfoLabel release], _regInfoLabel = nil;
    [super dealloc];   //此处是崩溃的地方,
}

JSPatch(替换LoginView的初始化方法,并且传入参数frame和aRegInfo):

require('UIColor,GSUtil,UITextField,UILabel,UIFont,UIButton');
defineClass('LoginView', {
            initWithFrame_regInfo: function(frame, aRegInfo) {
            self = self.super().initWithFrame(frame);
            if (self) {
            // Initialization code
            var _cellNumTextField = UITextField.alloc().initWithFrame({x:8, y:20, width:290, height:30});
            self.setCellNumTextField(_cellNumTextField);
            self.addSubview(_cellNumTextField);

            var _regInfoLabel = UILabel.alloc().initWithFrame({x:14, y:55, width:276, height:90});
            _regInfoLabel.setText(aRegInfo);
            self.setRegInfoLabel(_regInfoLabel);
            self.addSubview(_regInfoLabel);
            return self;
    }
});