2012-01-14 63 views
0

我的iPhone應用程序崩潰後提出了4個低內存警告,儀器顯示沒有內存泄漏,但在內存分配實時字節上升到4.7MB和超過所有字節高達79.0 MB和應用程序崩潰這一點低內存警告後應用程序崩潰

任何幫助,將不勝感激

for (int i = 0; i<3; i++) 
{ 

    UIImage *rendered_image; 
    UIGraphicsBeginImageContextWithOptions(sub_view.bounds.size, NO, 0.0); 

    [appdelegate.arrimages removeAllObjects]; 
    [appdelegate.arranimations removeAllObjects]; 

    NSString *oldgroup = [[NSString alloc] init]; 
    NSString *currentgroup = [[NSString alloc] init]; 

    for(int i=0; i<[sub_view.data count]; i++) 
    { 

     oldgroup = (i>0) ? [sub_view.group objectAtIndex:(i-1)] : [sub_view.group objectAtIndex:i]; 
     currentgroup = [sub_view.group objectAtIndex:i]; 

     /* 
     IF DIFFERENT GROUP NAME RECEIVED 
     1-GET NEW INSTANCE OF IMAGE 
     2-SAVE PREVIOUS IN ARRAY 
     */ 



    if (![oldgroup isEqualToString:currentgroup]) 
     { 

      rendered_image = UIGraphicsGetImageFromCurrentImageContext(); 

      [self SaveImagesOfAnimation:[self compressImageDownToPhoneScreenSize:rendered_image]]; 

      [appdelegate.arranimations addObject:[sub_view.anim objectAtIndex:i]]; 

      UIGraphicsEndImageContext(); 
      UIGraphicsBeginImageContextWithOptions(sub_view.bounds.size, NO, 0.0); 

     } 

     id element = [sub_view.data objectAtIndex:i];  

     color = [sub_view.fillColor objectAtIndex:i]; 

     [color setFill]; 
     [element fill]; 

     [[UIColor blackColor] setStroke]; 
     [element stroke]; 

    } 

    rendered_image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    [self SaveImagesOfAnimation:[self compressImageDownToPhoneScreenSize:rendered_image]]; 

} 
+1

儀器還可以顯示您分配的物體種類和確切的堆棧軌跡,因此您應該能夠快速找出它。 – Costique 2012-01-14 07:46:07

+0

檢查此鏈接http://stackoverflow.com/questions/6425043/how-i-can-display-an-alert-when-i-received-memory-warning-level-2-in-iphone-sdk/6425084# 6425084 – 2012-01-14 18:41:28

回答

0

增加內存的使用沒有泄漏意味着你存儲,你從來沒有發佈數據,而你仍持有它參考。

這通常意味着當你放入更多數據時會自動增長的數據結構之一,比如NSMutableArray,就是怪罪。他們會高興地保存你添加給他們的所有數據,內存分析器不會發現任何泄漏,因爲放入NSMutableArray的項目 - 根據定義 - 從未釋放,並且沒有檢測到泄漏,因爲從陣列中引用了它們。

編輯:如果你沒有明顯的地方看,一般的解決方法是看頂部@Costique的評論;

儀器也可以顯示出一種你分配的對象和 確切的堆棧跟蹤,所以你應該能夠很快算出它 出來。

+0

感謝您的回覆以下是我的代碼,請您指出哪裏出了問題。 – 2012-01-14 07:16:23

+0

我更新了問題,並把代碼請檢查 – 2012-01-14 07:46:46

+0

仍在等待一些人可以把我放在正確的軌道 – 2012-01-14 08:30:01

相關問題