2010-10-14 107 views
0

我正在嘗試開發TilesGame並且我處於最後階段。但是我的項目開始顯示意想不到的行爲。在隨機時間它顯示內存警告級別= 1,級別= 2然後, 編程接收信號:「0」。 數據格式化程序暫時不可用,將在「繼續」後重新嘗試。 (未知錯誤加載共享庫「/Developer/usr/lib/libXcodeDebuggerSupport.dylib」) kill quit
我不知道我在哪裏做錯了。我有大量的ImageViews,但它們被正確分配和釋放。接收內存警告級別= 1,級別= 2然後崩潰

有什麼關於IBOutlets的?我在我的viewController的Dealloc方法中發佈了它們。

在ViewController.h

@property (nonatomic, retain) MyCustomButton *paveButton; 
@property (nonatomic, retain) MyCustomButton *slackenButton; 
@property (nonatomic, retain) MyCustomButton *tkeeperButton; 
@property (nonatomic, retain) MyCustomButton *spontButton; 

@property (nonatomic, retain) UIImageView *paveHammer; 
@property (nonatomic, retain) UIImageView *slackenHammer; 
@property (nonatomic, retain) UIImageView *tkeeperHammer; 
@property (nonatomic, retain) UIImageView *spontHammer; 
@property (nonatomic, retain) UIImageView *paveKnob; 

並在ViewController.m -

@synthesize paveButton; 
@synthesize slackenButton; 
@synthesize tkeeperButton; 
@synthesize spontButton; 
@synthesize paveHammer; 
@synthesize slackenHammer; 
@synthesize tkeeperHammer; 
@synthesize spontHammer; 
@synthesize paveKnob; 



- (void)dealloc { 
    [super dealloc]; 
[paveButton release]; 
[slackenButton release]; 
[tkeeperButton release]; 
[spontButton release]; 
[paveHammer release]; 
[slackenHammer release]; 
[tkeeperHammer release]; 
[spontHammer release]; 
[paveKnob release]; 

} 

我在哪裏做錯了嗎?任何幫助?
在此先感謝。

+0

這不會回答你的問題,但[超dealloc]應該__always__去你dealloc方法的末尾:) – deanWombourne 2010-10-14 13:17:08

回答

0

您使用過的圖像尺寸很大,這就是爲什麼它會導致錯誤「內存警告」。請嘗試使用尺寸更小,分辨率更低的圖像。

所有最好的。

0

該應用試圖使用比可用更多的內存。使用儀器檢查泄漏和分配。也許嘗試更少的瓷磚或更小的瓷磚。

2

它看起來是因爲它使用了太多的內存(雖然我猜你已經知道了!)

釋放的東西在你的dealloc方法並不意味着他們將得到釋放,如果有喜歡你的應用程序被打死記憶不足。

你需要釋放任何IBOutlets是這樣的:當內存不足的警告,會

- (void)didReceiveMemoryWarning { 
    // Releases the view if it doesn't have a superview. 
    [super didReceiveMemoryWarning]; 

    // Release any cached data, images, etc that aren't in use. 
    [self setPaveButton:nil]; 
} 

調用此方法。

只有在視圖重新加載的情況下,才能在viewDidLoad方法中重新創建內容。

+0

謝謝,我要去試試這個。 – DeFantom 2010-10-18 04:12:53

+0

只是想添加更多關於[self setPaveButton:nil]的信息;這條線屬性將首先釋放舊按鈕,然後嘗試保留新對象。這意味着這條線將釋放舊對象並保留零,這是沒有什麼。這是很好的做法。 – 2012-02-29 03:06:38

+0

其實,我的答案是完全錯誤的:(如果你得到的內存不足警告,但仍然顯示視圖,那麼你想要做的最後一件事是忘記你放你的按鈕!釋放'IBOutlet's應該在'viewDidUnload ':( – deanWombourne 2012-02-29 10:40:30

0

感謝所有回覆我的問題和感謝Ur的Advices.I已修復我的錯誤,我真的在我的代碼中造成了所有這些麻煩愚蠢的錯誤。

我有大量的ImageViews,但他們分配和正確釋放。

其實這是不對的。我有一個ImageAnimation而且我也像這 -

- (void) createBorderGlessEffect 
{ 
    borderImage.animationImages = [[NSArray alloc]initWithObjects: 
            [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BorderG_1" ofType:@"png"]], 
            [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BorderG_2" ofType:@"png"]], 
            [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BorderG_3" ofType:@"png"]], 
            [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BorderG_4" ofType:@"png"]], 
            [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BorderG_5" ofType:@"png"]], 
            [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BorderG_6" ofType:@"png"]], 
            [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BorderG_7" ofType:@"png"]], 
            [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BorderG_8" ofType:@"png"]], 
            [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BorderG_9" ofType:@"png"]], 
            [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BorderG_10" ofType:@"png"]], 
            [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BorderG_11" ofType:@"png"]], 
            [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BorderG_12" ofType:@"png"]], 
            [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"BorderG_13" ofType:@"png"]], 
            nil]; 
    [borderImage setAnimationDuration:0.6f]; 
    [borderImage setAnimationRepeatCount:1]; 
    [borderImage startAnimating]; 
} 

此方法在我的項目一再呼籲,並期待在粗體部分我的代碼,我已經分配的NSArray 13個的對象這是從來沒有被釋放。

我現在做這個 -

borderImage.animationImages = [NSArray arrayWithObjects:... 

這個答案實際上並不涉及什麼我曾問過,但我覺得,我有責任在這裏提到我的解決方案。

再次感謝。

+0

爲什麼每個單詞都以大寫字母開頭;他們並不真正需要!您應該將此答案標記爲已接受(大滴答聲按鈕),以便人們知道此問題已得到回答:) – deanWombourne 2012-02-29 10:35:22