0

私のアプリには、ネットワークタスクを処理するServerRequestというNSOperationクラスがあります。楽器によると、それは狂ったように漏れています。さらに、instrumentsは、NSOperationではないにもかかわらず、リクエストをビルドするコードがリークしていると言います。しかし、私は自動解放プールの設定に関してAppleのアドバイスに従ったので、何が問題になるのか理解できません。誰か助けてもらえますか?

私のコードの一部は以下のとおりです。

-(void) main {
 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 self.data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];  // lots of leakage here
 [self postResult]; // leakage here too
 [pool release];
}

およびpostResultメソッド(リークしていません):

-(void) postResult {
// error handling code here

 if (![self isCancelled])
 {
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  NSMutableDictionary *resultDictionary = [[NSMutableDictionary alloc]init];
  if (self.data!=nil)
   [resultDictionary setObject:self.data forKey:kDataKey];
  if (self.response!=nil)
   [resultDictionary setObject:self.response forKey:kResponseKey];
  if (self.error!=nil)
   [resultDictionary setObject:self.error forKey:kErrorKey];
  NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
  NSNotification *notification = [NSNotification notificationWithName: kDownloadCompleteName object: self userInfo: resultDictionary];
  [resultDictionary release];
  [center postNotification: notification];

  [pool drain];
 }
}

最後に、dealloc:

- (void) dealloc {
 self.request = nil;
 self.data = nil;
 self.mutableData = nil;
 if (!self.error)
  self.error = nil;
 if (!self.response)
  self.response = nil;
 [super dealloc];
}
4

1 に答える 1

0

self.var = nilデコンストラクターで変数を解放するためのセッターアプローチを避けることを推奨する人もい-deallocます。

[var release], var = nil古い実証済みのアプローチを試しましたか?

于 2010-02-25T22:02:21.257 に答える