簡體   English   中英

(iPhone)UIImage占用多少內存?

[英](iphone) how much memory UIImage takes up?

我遇到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; } 

檢查內存分配

如果要測試特定圖像,請在使用Instruments時在iPhone / Simulator中運行應用程序。

使用“分配”配置文件運行

確保選擇適當的目標。 運行程序時,您將看到特定分配所占用的內存空間。


在跑步的時候

您將看到窗口中分配的對象。 像這一個,我附加iTunes。

在跑步的時候

顯然,圖像越大,您將使用的內存就越大,一次加載到內存中的圖像量也是如此。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM