2010-10-08 128 views
0

我在這個初學者:)IPhone應用程序崩潰的設備,但工程對iPhone

我有一個應用程序,它改變時,按下一個按鈕一個UIImageView的圖像,每幅圖像約爲200 KB,在運行時在模擬器中運行正常,我可以多次更換圖像而不會出現問題。

在我的設備上運行時(ipod touch)它加載正常,它緩慢地通過約4張圖像,然後崩潰。當我使用Allocations性能工具運行它時,它會在總字節數達到2.75 megs時崩潰。生活分配的數量大約是8000(這是高嗎?)。

我的控制檯讀取該

Program received signal: 「0」. 
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib") 

我使用「泄漏」性能工具也嘗試過,並沒有發現任何泄漏。

我.h文件中加載圖像和uimageview這樣的:

@property(retain, nonatomic) IBOutlet UIImageView* myUIImageView; 
@property(nonatomic, retain) UIImage *image; 

另外,我釋放這些是這樣的:

- (void)dealloc { 
[super dealloc]; 
[myUIImageView release]; 
[image release]; 
} 

我還添加了這一點,但它似乎沒有有什麼區別:

- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 
    [myUIImageView release]; 
    [image release]; 
    // Release any cached data, images, etc that aren't in use. 
} 

我不知道還有什麼要嘗試在這一點上,任何調試技巧的建議會不勝感激,如何解決像這樣的內存問題的任何指針將非常有幫助, 謝謝!

此外,對不起忘了加上形象改變代碼:

- (IBAction)myButton { 

    static NSUInteger counter = 0; 

    counter++; 

    if (counter == 1) { 
     myUIImageView.image = [UIImage imageNamed:@"image1.jpg"]; 
    } 
    else { 
     myUIImageView.image = [UIImage imageNamed:@"image2.jpg"]; 
      counter = 0; 
    } 
} 

回答

2

你的影像變更的代碼看起來不錯,但我建議這些變化:

您應該設置myUIImageView爲零你viewDidUnload方法:

- (void)viewDidUnload { 
    // release retained subviews of main view 
    self.myUIImageView = nil; 
} 

didReceiveMemoryWarning,你應該設置圖像零,而不是發送釋放:

self.image = nil; 

兩個didReceiveMemoryWarning[image release]dealloc可能會導致雙重版本。

此外,請勿在didReceiveMemoryWarning中發佈myUIImageView

你真的使用image伊娃嗎?看起來您正在將圖像直接分配給UIImageView。顯然,未使用的伊娃不會引起問題,但我只是想知道爲什麼它在那裏。

+0

謝謝你的幫助喬希,我在我的圖像改變代碼中添加 – 2010-10-08 23:47:33

+0

修改我的答案作爲迴應。;-) – 2010-10-08 23:51:17

+0

嗯,我不太確定如果我使用伊娃,我在我的.m文件頂部合成圖像:@synthesize image;因爲它警告我即使它正在編譯也不存在,我也應該將myUIImageView設置爲didReceiveMemoryWarning中的nil以及圖像嗎?或者可以在這裏發佈它。 – 2010-10-08 23:55:59

0

是您使用的代碼來改變形象?確保你沒有重新分配圖像或imageview。

+0

感謝您的迴應本,請參閱我的編輯。 – 2010-10-08 23:40:59