這是一個簡單的應用程序,從我的資源文件夾獲取30張圖片,在viewDidLoad
期間將它們放入NSMutableArray
,然後根據加速度計數據更改圖片。我有一個來自IB的UIImageView
覆蓋整個視圖,當加速度計更新其信息時,它將uiimageview.image
交換爲差異圖。作品約10秒鐘,然後崩潰與此:我的iPhone應用程序中的內存泄漏在哪裏?
Program received signal: 「0」.
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib")
在這裏四處尋找後,它聽起來就像是一個內存泄漏。以下是我正在使用的代碼:
Interface:
{
UIAccelerometer *accel;
IBOutlet UIImageView *pic;
NSMutableArray *picArr;
}
Implementation:
- (void)viewDidLoad
{
[super viewDidLoad];
picArr = [[NSMutableArray alloc] init]; //array of pics to be used
NSString *path = [[NSString alloc] init]; //dynamic path of images to save to array
for (int i = 1; i <= 30; i++)
{
path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"nativity_test_%i", i] ofType:@"jpg"];
[picArr addObject:[[UIImage alloc] initWithContentsOfFile:path]];
}
accel = [UIAccelerometer sharedAccelerometer];
accel.delegate = self;
accel.updateInterval = 0.5f;
[path release];
pic.image = [picArr objectAtIndex:15];
}
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
if(acceleration.y < 0.0f) //goes thru the tilted left pics
{
for (int i = 0; i <= 15; i++)
{
if(acceleration.y >= (-(15.0f-(double)i)/30.0f) && acceleration.y < (-(14.0f-(double)i)/30.0f))
{
pic.image = [picArr objectAtIndex:i+1];
}
}
}
else if(acceleration.y > 0.0f) //goes thru tilted right pics
{
for (int i = 1; i <= 14; i++)
if(acceleration.y > ((double)i/30.0f) && acceleration.y <= ((double)(i+1)/30.0f))
{
pic.image = [picArr objectAtIndex:i+15];
}
}
}
如果我遺漏了任何相關信息,請讓我知道。
實例變量是不是屬性有關係嗎? – Marty 2010-11-08 23:15:07