我在这里的另一个线程上得到了这段代码,它运行良好,但它泄漏了,我不知道如何释放它。我尝试将“autorelease”语句添加到 GoToNext alloc 行。它没有帮助。有谁知道如何正确处理这个?
webView.delegate = [[GoToNext alloc] initWithTarget:self andNext:@selector(loadUpdateGraph)]; //leak
这是 GoToNext 代码:
。H
@interface GoToNext : NSObject <UIWebViewDelegate> {
id __weak target;
SEL next;
}
-(id)initWithTarget:(id)target andNext:(SEL)next;
-(void)webViewDidFinishLoad:(UIWebView *)webView;
@end
.m
#import "GoToNext.h"
@implementation GoToNext
-(id)initWithTarget:(id)_target andNext:(SEL)_next {
self = [super init];
if (self) {
target = _target;
next = _next;
}
return self;
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
[target performSelector:next];
}
@end