Мое приложение падает после нескольких поворотов - PullRequest
1 голос
/ 16 мая 2010

Мое приложение падает, когда я пытаюсь повернуть его несколько раз. Сначала я подумал, что это просто iPhone Simulator, поэтому я загрузил приложение на iPod touch, и оно упало после меньшего количества вращений подряд. Я подозреваю, что это утечка памяти в одном из моих методов поворота. Единственное место, где я могу думать, что причиной аварии является willRotateToInterfaceOrientation:duration:. Я добавил / расширил только два метода, связанных с вращением: shouldAutorotateToInterfaceOrientation: и willRotateToInterfaceOrientation:duration, и я не думаю, что это первый, потому что он содержит только два слова: return YES;. Вот мой willRotateToInterfaceOrientation:duration: метод, чтобы вы могли просмотреть его и посмотреть, где возможная утечка памяти.

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration 
{
 UIFont *theFont;


 if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight))
 {
  theFont = [yearByYear.font fontWithSize:16.0];
  yearByYear.font = theFont;
  [theview setContentSize:CGSizeMake(460.0f, 635.0f)];
 }
 else
 {
  theFont = [yearByYear.font fontWithSize:10.0];
  yearByYear.font = theFont;
  [theview setContentSize:CGSizeMake(300.0f, 460.0f)];
 }

 [theFont release];
}

yearByYear - UITextView, а просмотр - UIScrollView.

1 Ответ

4 голосов
/ 16 мая 2010

Вы не должны выпускать theFont. Вы не являетесь владельцем объекта.

Вы также можете упростить то, что вы делаете:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration  {

   if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) {
      yearByYear.font = [yearByYear.font fontWithSize:16.0]
      [theview setContentSize:CGSizeMake(460.0f, 635.0f)];
   }
   else
   {
      yearByYear.font = [yearByYear.font fontWithSize:10.0]
      [theview setContentSize:CGSizeMake(300.0f, 460.0f)];
   }
}

Полное избавление от theFont.

...