1

当我尝试旋转它多次时,我的应用程序崩溃了。我一开始以为它只是 iPhone 模拟器,所以我将应用程序加载到 iPod touch 上,连续旋转较少后它就崩溃了。我怀疑这是我的一种旋转方法中的内存泄漏。我唯一能认为导致崩溃的地方是willRotateToInterfaceOrientation:duration:. 我添加/扩展的唯一两种与旋转相关的方法是shouldAutorotateToInterfaceOrientation:andwillRotateToInterfaceOrientation: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 是 aUITextView而 theview 是 a UIScrollView

4

1 回答 1

4

你不应该释放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彻底摆脱。

于 2010-05-16T12:16:18.390 回答