我已经注意到有关此主题的其他几个线程,并尝试使用以下代码包装我的线程代码: NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; [池释放];
但错误仍然存在。
我正在使用静态方法来实例化单词字典。这是一些代码:
-(id)init
[NSThread detachNewThreadSelector:@selector(loadDictionary:) toTarget:[IntroScreen class] withObject:nil];
[NSThread setThreadPriority:1.0];
return self;
}
+(void)loadDictionary:(id)param
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
[[SimpleAudioEngine sharedEngine] preloadEffect:@"click.wav"];
[[SimpleAudioEngine sharedEngine] preloadEffect:@"pop.wav"];
[[SimpleAudioEngine sharedEngine] preloadEffect:@"dink.wav"];
[[SimpleAudioEngine sharedEngine] playBackgroundMusic:@"musicloop.wav"];
[WordDictionary configDictionary];
[pool release];
}
+(void)configDictionary
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Serializer * mySerializer = [[Serializer alloc] init];
[WordDictionary setDictionary:[mySerializer readApplicationPlist:@"x"]];
NSString * string;
NSString *filePath = [[[NSBundle mainBundle] resourcePath]
stringByAppendingPathComponent:@"x.txt"];
NSString *info = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
NSArray *arrayOfLines = [info componentsSeparatedByString:@"\r\n"];
[WordDictionary setDictionary:[[NSMutableDictionary alloc] init]];
[NSMutableDictionary dictionaryWithContentsOfFile:filePath];
int len = [arrayOfLines count];
for(int i = 0; i < len; i++)
{
string = [arrayOfLines objectAtIndex:i];
NSString * blankString = [NSString stringWithString:@""];
[[WordDictionary dictionary] setObject:blankString forKey:string];
double calc = ((double)i / (double)len) * 100.0;
[WordDictionary setProgress:(int)calc];
}
[mySerializer writeApplicationPlist:[WordDictionary dictionary] toFile:@"s"];
[WordDictionary setProgress:100];
[pool release];
}
关于将静态类方法与新的选择器线程一起使用,我应该知道些什么?
谢谢您的帮助