2011-01-07 47 views
0

我遇到了UIImage內存大小問題。(iphone)UIImage佔用多少內存?

  1. 當你有320個* 320分辨率的圖像數據(PNG),當將圖像加載到存儲器,
    使用[UIImage的imageWithData:],將所得的UIImage將佔用320 * 320 * 4?

  2. 屏幕大小(分辨率)會影響圖像的內存使用情況嗎?

  3. 下面的代碼會佔用myImage的兩倍內存大小還是單個圖像內存大小? (320 * 320 * 4)* 2 vs(320 * 320 * 4)?或者是其他東西?

    UIImage* myImage = [UIImage imageWithData:];  
    myImage = [myImage scaleToSize:]; 
    

    當scaleToSize作爲

    - (UIImage*)scaleToSize:(CGSize)size 
    { 
        // Create a bitmap graphics context                        
    
    
        // This will also set it as the current context                                                        
        UIGraphicsBeginImageContext(size); 
    
        // Draw the scaled image in the current context                                                        
        [self drawInRect:CGRectMake(0, 0, size.width, size.height)]; 
    
        // Create a new image from current context                                                         
        UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext(); 
    
        // Pop the current context from the stack                                                         
        UIGraphicsEndImageContext(); 
    
        // Return our new scaled image                                                            
        return scaledImage; 
    } 
    

回答

0
顯然

越大,圖像越存儲器將使用,同樣適用於圖像的量加載到內存中立刻被定義。

2

,如果你想測試特定的圖像,而使用儀器運行在iPhone /模擬器應用程序檢查內存分配

Run with the Allocations profile

確保你選擇合適的目標。當你運行程序時,你會看到特定分配佔用的內存空間。


當跑

你會看到窗口中分配的對象。就像這個,我附加了iTunes。

While running