IOS-內(nèi)存檢測(cè)以及優(yōu)化
PS:開(kāi)始寫(xiě)這個(gè)系列的筆記:主要是對(duì)過(guò)去自己比較模糊的一些概念進(jìn)行測(cè)試,明確結(jié)果,提高自己
IOS 應(yīng)用如果占用系統(tǒng)的內(nèi)容過(guò)大(8GB),就會(huì)造成應(yīng)用直接被系統(tǒng)以崩潰的形式關(guān)閉,一次控制應(yīng)用占用的內(nèi)存大小是非常重要的事情。
現(xiàn)在我們來(lái)看看,一個(gè)空的應(yīng)用占據(jù)的內(nèi)容的大?。?/div>
測(cè)試環(huán)境:xCode 5.0/IOS 5
啟動(dòng)一個(gè)空應(yīng)用,占用的內(nèi)存為 2.6MB,占據(jù)應(yīng)用崩潰的閥值為 0.03%
1:關(guān)于導(dǎo)航條的 Push和popup的測(cè)試結(jié)果
[self.navigationController pushViewController:m_navanimated:YES];
[self.navigationController popViewControllerAnimated:YES];
對(duì)于
pushViewController ,會(huì)將對(duì)應(yīng)的ViewController對(duì)象的引用計(jì)數(shù)器+1
popViewControllerAnimated 會(huì)將對(duì)應(yīng)的ViewController對(duì)象的引用計(jì)數(shù)器-1
但是有一點(diǎn)需要明確的是,對(duì)于函數(shù)
-(void)dealloc
{
//Objects release here
[super deallco];
}
只有在該引用計(jì)數(shù)器的值==0的時(shí)候才會(huì)調(diào)用,這個(gè)是必須牢記的。
在執(zhí)行函數(shù)[self.navigationController popViewControllerAnimated:YES];的時(shí)候,如果彈出的ViewController對(duì)應(yīng)的引用計(jì)數(shù)器為0,那么也會(huì)執(zhí)行dealloc 函數(shù)。
所以再使用
[self.navigationController pushViewController:m_navanimated:YES];
[self.navigationController popViewControllerAnimated:YES];
棧函數(shù)對(duì)的時(shí)候,為了釋放內(nèi)存,我們可以這么使用
Nav_1 *m_nav = [[[Nav_1 alloc] initWithNibName:nil bundle:nil] autorelease];
[self.navigationController pushViewController:m_nav animated:YES];
這樣就最大限度的節(jié)省了寶貴的內(nèi)存空間
posted on 2014-08-04 09:56 順其自然EVO 閱讀(426) 評(píng)論(1) 編輯 收藏 所屬分類: 測(cè)試學(xué)習(xí)專欄
評(píng)論
# re: IOS-內(nèi)存檢測(cè)以及優(yōu)化[未登錄](méi) 2014-10-15 16:45 Andy
最后Nav_1 *m_nav = [[[Nav_1 alloc] initWithNibName:nil bundle:nil] autorelease];
[self.navigationController pushViewController:m_nav animated:YES];
這樣就節(jié)省了內(nèi)容,是什么原因,沒(méi)看懂 回復(fù) 更多評(píng)論
只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。 | ||
![]() |
||
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問(wèn)
管理
|
||
相關(guān)文章:
|
||