2013-07-13 271 views
3

當我測試我的應用程序在儀器內存泄漏我什麼也沒找到(使用模擬器運行)。但是當我在移動中運行它,然後檢查,還有UIKit中的對象很多泄漏。這發生在每一個角度。在模擬器沒有這樣的泄漏顯示。在UIKit中獲取內存泄漏?

下面是其中一些泄漏發生在儀器的屏幕截圖。

enter image description here

當我從HomeView搬到secondViewController,無泄漏found.If再回來家,這麼多的泄漏被發現。那麼,是不是意味着我必須釋放所有在第二個視圖中使用的UI對象。爲了您的信息,以下是我在secondView中使用的UI對象。

1.Two Background UIImageView 
2.One TitleBar UIImageView 
3.3 UIButtons(Back,left and right button for iCarousel) 
4.One iCarousel view 
5.UIPageController(For this I have used a third Party code SMPageControl) 
6.One title label. 

注:礦是不ARC代碼。

這兒還有沒有人遇到這個問題before.How我可以克服這個問題,因爲我在每一個視圖這個問題在我的這個App.Because,我的應用程序越來越內存華林頻繁,經常崩潰。

謝謝。

下面是該視圖的我實現文件。

EDIT1:

@implementation CatalogueViewController 

@synthesize deptCarousel = _deptCarousel; 
@synthesize carouselItems = _carouselItems; 
@synthesize categorymAr  = _categorymAr; 
@synthesize spacePageControl = _spacePageControl; 
@synthesize wrap; 

- (void)dealloc { 
    _deptCarousel = nil; 
    [_categorymAr    release]; 
    _categorymAr    = nil; 
    _deptCarousel.delegate  = nil; 
    _deptCarousel.dataSource = nil; 
    [_deptCarousel    release]; 
    [_carouselItems    release]; 
    [viewGesture release]; 
    viewGesture = nil; 
    [_spacePageControl release]; 
    _spacePageControl = nil; 
    imgViewBG = nil; 
    imgViewBG2 = nil; 
    btnPrev = nil; 
    btnNext = nil; 
// [self releaseObjects]; 
    [super dealloc]; 
} 


- (IBAction) btnBackClicked { 
    [self.navigationController popViewControllerAnimated:YES]; 
} 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (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. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.title = NSLocalizedString(@"catalogue", @"Catalogue"); 

    // Do any additional setup after loading the view from its nib. 

    _deptCarousel.type = iCarouselTypeLinear; 
    _deptCarousel.scrollSpeed = 0.3f; 
    _deptCarousel.bounceDistance = 0.1f; 
    _deptCarousel.scrollToItemBoundary = YES; 
    _deptCarousel.stopAtItemBoundary = YES; 
    [_deptCarousel setScrollEnabled:NO]; 

    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeNext:)]; 
    swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft; 
    [viewGesture addGestureRecognizer:swipeLeft]; 
    [swipeLeft release]; 

    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipePrev:)]; 
    swipeRight.direction = UISwipeGestureRecognizerDirectionRight; 
    [viewGesture addGestureRecognizer:swipeRight]; 
    [swipeRight release]; 

    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)]; 
    [viewGesture addGestureRecognizer:singleTap]; 
    [singleTap release]; 

    _carouselItems  = [[NSMutableArray alloc] initWithCapacity:1]; 
    _categorymAr  = [[NSMutableArray alloc] initWithCapacity:1]; 
    [self addCatalogues]; 
    _spacePageControl.numberOfPages = [_categorymAr count]; 
    [_spacePageControl setPageIndicatorImage:[UIImage imageNamed:[email protected]"Marker1.fw.png" : @"Markeri.png"]]; 
    [_spacePageControl setCurrentPageIndicatorImage:[UIImage imageNamed:[email protected]"Marker-Highlight.png" : @"Marker-Highlight_i.png"]]; 
    [_spacePageControl addTarget:self action:@selector(spacePageControl:) forControlEvents:UIControlEventValueChanged]; 

} 



- (void)spacePageControl:(SMPageControl *)sender{ 
    [_deptCarousel scrollToItemAtIndex:sender.currentPage animated:YES]; 
} 

- (void) addCatalogues { 
    [_categorymAr addObjectsFromArray:[[DBModel database] categoryList]]; 

    for (int i = 0; i < [_categorymAr count]; i++) { 
     [_carouselItems addObject:[NSNumber numberWithInt:i]]; 
    } 
    [_deptCarousel reloadData]; 
} 

- (void)viewDidUnload{ 

    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (void)viewWillAppear:(BOOL)animated 
{ 
    [self phoneType]; 
    [super viewWillAppear:animated]; 
    if (IS_IPAD) { 
     UIInterfaceOrientation statusBarOrientation = [[UIApplication sharedApplication] statusBarOrientation]; 
     [self handleOrientation:statusBarOrientation]; 
    } 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
} 


- (void) phoneType{ 

    if(!IS_IPAD){ 
     if(IS_IPHONE5){ 
      imgViewBG.image = [UIImage imageNamed:@"Background5_5.jpg"]; 
      imgViewBG.center = CGPointMake(162,265); 
      imgViewBG2.image = [UIImage imageNamed:@"Background11_5.png"]; 
      _spacePageControl.center = CGPointMake(160, 478); 
      _deptCarousel.center = CGPointMake(160, 355); 
      viewGesture.center = CGPointMake(160, 355); 
      btnPrev.center = CGPointMake(25, 355); 
      btnNext.center = CGPointMake(295, 355); 
     } 
     else{ 
      imgViewBG.image = [UIImage imageNamed:@"Background5.jpg"]; 
      imgViewBG2.image = [UIImage imageNamed:@"Background9.png"];    
     } 
    } 

} 


-(void)textFieldDidBeginEditing:(UITextField *)textField{ 

    textFieldSearch.placeholder = @""; 
    UIButton *clearButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 20)]; 
    [clearButton setImage:[UIImage imageNamed:[email protected]"Btn_X_Large.fw.png":@"Btn_X.fw.png"] forState:UIControlStateNormal]; 
    [clearButton addTarget:self action:@selector(btnClearTextField) forControlEvents:UIControlEventTouchUpInside]; 
    [textFieldSearch setRightViewMode:UITextFieldViewModeAlways]; 
    [textFieldSearch setRightView:clearButton]; 
    [clearButton release]; 

} 

-(void)textFieldDidEndEditing:(UITextField *)textField{ 
    [textFieldSearch setRightView:nil]; 
    if ([textFieldSearch.text isEqualToString:@""]) { 
     textFieldSearch.placeholder = NSLocalizedString(@"hud_search_for_a_product_here",@""); 
    } 
} 

-(IBAction)btnClearTextField{ 
    textFieldSearch.text = @""; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskAll; 
} 



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if (IS_IPAD) { 
     return YES; 
    } else { 
     return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 
    } 
} 

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ 
    if (IS_IPAD) { 
     [self handleOrientation:toInterfaceOrientation]; 
    } 
} 

- (void) handleOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 



    if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { 
     imgViewBG.image = [UIImage imageNamed:@"Background_Catalogue_P.jpg"]; 
     imgViewBG2.image = [UIImage imageNamed:@"Background_Overlay_P.fw.png"]; 
     btnPrev.center = CGPointMake(90, 640); 
     btnNext.center = CGPointMake(677, 640); 
     textFieldSearch.frame = CGRectMake(187, 54, 418, 25); 
     _deptCarousel.frame = CGRectMake(235, 250, 300, 800); 
     _spacePageControl.center = CGPointMake(385, 920); 
     viewGesture.center = CGPointMake(385, 658); 

    }else { 
     imgViewBG.image = [UIImage imageNamed:@"Background_Catalogue_L.jpg"]; 
     imgViewBG2.image = [UIImage imageNamed:@"Background_Overlay_L.fw.png"]; 
     btnPrev.center = CGPointMake(54, 385); 
     btnNext.center = CGPointMake(640, 385); 
     textFieldSearch.frame = CGRectMake(240, 55, 567, 25); 
     _deptCarousel.frame = CGRectMake(50, 250, 600, 300); 
     _spacePageControl.center = CGPointMake(346, 660); 
     viewGesture.center = CGPointMake(347, 405); 

    } 
} 

- (IBAction)btnDepartmentClicked:(id)sender { 
    int btnTag = [sender tag]; 
    ProductCategoriesViewController *productView = [[ProductCategoriesViewController alloc] initWithNibName:@"ProductCategoriesView" bundle:nil]; 
    if (btnTag == 0) { 
     [productView setStrTitle:NSLocalizedString(@"women", @"Women")]; 
    }else if (btnTag == 1) { 
     [productView setStrTitle:NSLocalizedString(@"men", @"Men")]; 
    } else { 
     [productView setStrTitle:NSLocalizedString(@"sports", @"Sports")]; 
    } 
    [self.navigationController pushViewController:productView animated:YES]; 

    [productView release]; 
} 


- (BOOL) textFieldShouldReturn:(UITextField *)textField { 
    [textField resignFirstResponder]; 
    [Flurry logEvent:@"Product searched" withParameters:[NSDictionary dictionaryWithObjectsAndKeys:textField.text,@"1", nil]]; 
    [self productSearch:textField.text isBar:NO isQR:NO]; 
    return YES; 
} 

- (void) productSearch:(NSString *)_searchText isBar:(BOOL)_isBar isQR:(BOOL)_isQr { 
    if ([_searchText isEqualToString:@""]) { 
     return; 
    } 

    NSMutableArray *ProductList = [[NSMutableArray alloc] init]; 
    [ProductList addObjectsFromArray:[[DBModel database] productSearch:_searchText isBar:_isBar isQR:_isQr]]; 
    if ([ProductList count] == 0) { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"product", @"") 
                 message:NSLocalizedString(@"cannot_find_product", @"") 
                 delegate:nil 
               cancelButtonTitle:NSLocalizedString(@"ok", @"") 
               otherButtonTitles:nil]; 
     [alert show]; 
     [alert release];   
    } else { 
     GeneralProductListViewController *generalProductList = [[GeneralProductListViewController alloc] initWithNibName:[email protected]"GeneralProductListView~iPad": @"GeneralProductListView" bundle:nil]; 
     [generalProductList setMArProducts:ProductList]; 
     [self.navigationController pushViewController:generalProductList animated:YES]; 
     [generalProductList release]; 
    } 
    [ProductList release]; 
    } 


-(IBAction) spin:(id)sender { 


    if([sender tag]==0) 
    { 

     [_deptCarousel scrollToItemAtIndex:[self.deptCarousel currentItemIndex]+1 animated:YES]; 
//   [_deptCarousel scrollByNumberOfItems:1 duration:2.0]; 
     } 

    else{ 
    [_deptCarousel scrollToItemAtIndex:[self.deptCarousel currentItemIndex]-1 animated:YES]; 

    } 

} 

-(void)swipeNext:(UISwipeGestureRecognizer *)recognizer{ 

    [_deptCarousel scrollToItemAtIndex:[self.deptCarousel currentItemIndex]+1 animated:YES]; 

} 

-(void)swipePrev:(UISwipeGestureRecognizer *)recognizer{ 

    [_deptCarousel scrollToItemAtIndex:[self.deptCarousel currentItemIndex]-1 animated:YES]; 

} 

-(void) handleSingleTap:(UITapGestureRecognizer *)recognizer{ 

    if ([_categorymAr count] > 0) { 

     ProductCategoriesViewController *prodCatView = [[ProductCategoriesViewController alloc] initWithNibName:IS_IPAD ? 
                @"ProductCategoriesView~iPad" : @"ProductCategoriesView" bundle:nil]; 
     Category *categoryObj = [_categorymAr objectAtIndex:[self.deptCarousel currentItemIndex]]; 
     [prodCatView setStrTitle:categoryObj.categoryName]; 
     [prodCatView setCategoryId:categoryObj.categoryId]; 
     [Flurry logEvent:@"Category List" withParameters:[NSDictionary dictionaryWithObjectsAndKeys:categoryObj.categoryName,[NSString stringWithFormat:@"%d",categoryObj.categoryId], nil]]; 
     [self.navigationController pushViewController:prodCatView animated:YES]; 
     [prodCatView release]; 
    } 
} 
//-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
// pageControl.currentPage = [self.deptCarousel currentItemIndex] ; 
//} 

#pragma mark 
#pragma mark NavigationBarViewDelegate metho 

- (void) navigationBackClicked { 
    [self.navigationController popViewControllerAnimated:YES]; 
} 

#pragma mark - 
#pragma mark iCarousel methods 

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel 
{ 
    return [_carouselItems count]; 
} 

- (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel 
{ 
    //limit the number of items views loaded concurrently (for performance reasons) 
    return NUMBER_OF_VISIBLE_ITEMS; 
} 

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index 
{ 
    Category *categoryObj = [_categorymAr objectAtIndex:index]; 
    //create a numbered view 
    UIView *view = nil; 
    NSString *imagePath = [[APP_CACHES_DIR stringByAppendingPathComponent:@"catalogues"] stringByAppendingString:[NSString stringWithFormat:@"/%d.jpg", categoryObj.categoryId]]; 
    if (![[NSFileManager defaultManager] fileExistsAtPath:imagePath]) { 
     view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:[email protected]"Gallery Placeholder.png":@"Gallery Placeholder.png"]] autorelease]; 
    } else { 
     view = [[[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[APP_CACHES_DIR stringByAppendingPathComponent:@"catalogues"] stringByAppendingString:[NSString stringWithFormat:@"/%d.jpg", categoryObj.categoryId]]]] autorelease]; 
    } 



    if (IS_IPAD) { 
     view.frame = CGRectMake(0, 0, 420, 420); 
    } else { 
     view.frame = CGRectMake(0, 0, 200, 200); 
    } 

// UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(view.bounds.origin.x, view.bounds.origin.y+view.bounds.size.height, view.bounds.size.width, 44)] autorelease]; 
// label.text = categoryObj.categoryName; 
// label.textColor = [UIColor blackColor]; 
// label.backgroundColor = [UIColor clearColor]; 
// label.textAlignment = UITextAlignmentCenter; 
// label.font = [UIFont fontWithName:@"Helvetica-Bold" size:IS_IPAD?26:14]; 
// [view addSubview:label]; 


    return view; 
} 

- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel 
{ 
    //note: placeholder views are only displayed on some carousels if wrapping is disabled 
    return INCLUDE_PLACEHOLDERS? 2: 0; 
} 

- (UIView *)carousel:(iCarousel *)carousel placeholderViewAtIndex:(NSUInteger)index 
{ 
    //create a placeholder view 
    UIView *view = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]] autorelease]; 
    UILabel *label = [[[UILabel alloc] initWithFrame:view.bounds] autorelease]; 
    label.text = (index == 0)? @"[": @"]"; 
    label.backgroundColor = [UIColor clearColor]; 
    label.textAlignment = UITextAlignmentCenter; 
    label.font = [label.font fontWithSize:50]; 

    _spacePageControl.currentPage = index; 


// [view addSubview:label]; 
    return view; 
} 

- (CGFloat)carouselItemWidth:(iCarousel *)carousel 
{ 
    //usually this should be slightly wider than the item views 
    return ITEM_SPACING; 
} 

- (CATransform3D)carousel:(iCarousel *)_carousel transformForItemView:(UIView *)view withOffset:(CGFloat)offset 
{ 
    //implement 'flip3D' style carousel 

    //set opacity based on distance from camera 
    view.alpha = 1.0 - fminf(fmaxf(offset, 0.0), 1.0); 

    //do 3d transform 
    CATransform3D transform = CATransform3DIdentity; 
    transform.m34 = _deptCarousel.perspective; 
    transform = CATransform3DRotate(transform, M_PI/8.0, 0, 1.0, 0); 

    return CATransform3DTranslate(transform, 0.0, 0.0, offset * _deptCarousel.itemWidth); 
} 

- (BOOL)carouselShouldWrap:(iCarousel *)carousel 
{ 
    //wrap all carousels 
// return NO; 
    return wrap; 
} 

- (void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index { 
    if (index == [self.deptCarousel currentItemIndex]) { 
     ProductCategoriesViewController *prodCatView = [[ProductCategoriesViewController alloc] initWithNibName:IS_IPAD ? 
                 @"ProductCategoriesView~iPad" : @"ProductCategoriesView" bundle:nil]; 
     Category *categoryObj = [_categorymAr objectAtIndex:index]; 
     [prodCatView setStrTitle:categoryObj.categoryName]; 
     [prodCatView setCategoryId:categoryObj.categoryId]; 
     [Flurry logEvent:@"Category List" withParameters:[NSDictionary dictionaryWithObjectsAndKeys:categoryObj.categoryName,[NSString stringWithFormat:@"%d",categoryObj.categoryId], nil]]; 
     [self.navigationController pushViewController:prodCatView animated:YES]; 
     [prodCatView release]; 
    } 
} 

-(void) carouselDidScroll:(iCarousel *)carousel{ 

// [_deptCarousel scrollToItemAtIndex:[self.deptCarousel currentItemIndex]+3 animated:YES]; 

// [_deptCarousel scrollByNumberOfItems:1 duration:1]; 

} 

- (void)carouselCurrentItemIndexUpdated:(iCarousel *)carousel{ 

    _spacePageControl.currentPage = [self.deptCarousel currentItemIndex]; 
} 

- (IBAction) myCart { 
    if ([[DBModel database] isShoppingListEmpty]) { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"at_shopping_cart", @"") 
                 message:NSLocalizedString(@"amsg_shopping_cart_empty", @"") 
                 delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", @"") otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
     return; 
    } 
    MyCartViewController *myCartView = [[MyCartViewController alloc] initWithNibName:IS_IPAD ? @"MyCartView~iPad" : @"MyCartView" bundle:nil]; 
    [self.navigationController pushViewController:myCartView animated:YES]; 
    [myCartView release]; 
} 
+4

我們需要代碼。你爲什麼不使用ARC? – Spectravideo328

+0

如果沒有看到一些代碼,我們無法回答這個問題。可能發生的事情(因爲你沒有使用ARC)是因爲你沒有正確地調用你的代碼中創建的對象上的release/autorelease。 –

+0

@ Spectravideo328請檢查我用於第二個視圖控制器的代碼。 – NSUserDefault

回答

1

第一:

你有可能和可見的泄漏,但我不知道這是否是你已經在儀器發現了同樣的泄漏:

這兩條線都在你的viewDidLoad方法

_carouselItems  = [[NSMutableArray alloc] initWithCapacity:1]; 
_categorymAr  = [[NSMutableArray alloc] initWithCapacity:1]; 

但是:viewDidLoad:被稱爲每個視圖是由它的控制器中加載時間。如果控制器清除(內存警告後爲例)的觀點,在第二viewDidLoad中你_carouselItems_categorymAr實例變量將失去參照先前創建的NSMutableArray,造成泄漏

所以,改變線路,並使用syntesized setter:

self.carouselItems  = [[[NSMutableArray alloc] initWithCapacity:1] autorelease]; 
self.categorymAr  = [[[NSMutableArray alloc] initWithCapacity:1] autorelease]; 

syntesized setter配置爲釋放之前的對象,然後分配一個新的。

但是:有可能您有另一次泄漏。 如果您可以簡單地重現泄漏(如果我明白,泄漏只是簡單地從一個VC移到另一個),您可以使用儀器的「heapshot」功能。

假設您泄漏出現從第一個VC移動到第二和回來:

  • 打開儀器與分配工具
  • 從第一個VC轉到第二個回來。
  • 按左邊的「標記堆」。一條線將出現。
  • 從第一個VC再次回到第二個回來。
  • 按「heapshot」再次
  • 做幾次(9-10)

的heapshot工具需要當時的生活目標的「快照」您按下按鈕,僅給出了區別。 如果有2-3個新對象,您將在列表中看到它。

這是一個很好的起點,調查泄漏。 看添附圖像:

Heapshot analysis

考慮,你必須通過查看創建的對象標記堆幾個時間和識別「假陽性」,在我的例子,你可以本身可能存在內存泄漏(heapshot5, 1,66KB),但在查看內容後,它不是 - >這是一個在那一刻開始的後臺任務。

此外,自動釋放池和一些UIKit中的對象的緩存可以顯示在heapshot東西的延遲,這就是爲什麼我說要多試幾次。

+0

使用setters很好,但是你需要使用'NSMutableArray'創建的autoreleased版本,或者它仍然是一個泄漏。 'self.carouselItems = [NSMutableArray array];'請注意,使用'initWithCapacity:'幾乎總是一個錯誤(特別是如此低的容量)。 (正如前面的評論所指出的那樣,ARC在任何情況下都是正確的答案。) –

+0

你是對的,他需要autorelease,因爲配置爲「retain」的setter發送另一個retain到新對象。我糾正了這個帖子。關於initWithCapacity和ARC的使用(我可以建議:-)我也同意,但是(關於ARC)我認爲調查一下泄漏並學習MRC的一些概念總是一個很好的做法;-)所以我建議海報只有在發現泄漏時才能遷移到ARC! – LombaX

+0

感謝guys.As你們都建議,我將我的代碼轉換爲ARC。現在沒有內存泄漏。還應該遵循其他建議來管理低內存警告。 – NSUserDefault

0

一個簡單的方法來檢測您的泄露來自是使用儀器的擴展的詳細視圖。

要做到「查看」表明點擊 - >「擴展的細節」,並以「泄密」的堆棧跟蹤一個右鍵菜單將出現。在那裏,你會很容易地發現每個泄漏的泄漏代碼,以及它們是否來自你的應用程序。

2

首先,正如前面提到的,使用ARC。沒有什麼可以做的事情可以改善內存管理。

無論您是否使用ARC,都應該使用訪問器訪問您的ivars(initdealloc除外)。正如@LombaX所指出的那樣,您在viewDidLoad中錯誤地設置了您的ivars。使用訪問器將有助於此。

您應該運行靜態分析儀,它會幫你找到其他內存錯誤。

我懷疑你有一個IBOutlet配置爲retain,並且你沒有發佈在dealloc。這是我在屏幕截圖中看到的泄漏的最可能原因。 ARC通常會自動消除這些問題。

這是非常可能的,你有一個保留循環。這通常不會顯示爲泄漏。您應該使用heapshot來調查。你的泄漏很小,他們可能不是記憶警告的真正原因。您想調查的內容(使用分配工具)實際上顯着增加了您的內存使用量。

但是第一個ARC。然後訪問者。然後刪除所有構建警告。然後刪除所有靜態分析器警告。然後使用分配工具。

邊注:事實上,它說的責任方「的UIKit」並不意味着這是UIKit中的錯誤。這僅僅意味着UIKit分配了之後泄漏的內存。泄漏的原因可能在其他地方。(表示,UIKit確實有幾個小漏洞,一般來說它們不應該給你帶來麻煩,但是你可能永遠無法擺脫iOS應用程序中100%的小漏洞。)

+0

非常感謝,非常好的建議。請告訴你是否清除我的問題。 – NSUserDefault