2009-09-03 62 views
1

以及我的問題「刪除MKMapView註釋導致泄漏。」我發現如果你創建一個基於視圖的項目,在視圖的NIB中添加一個UISearchBar和MKMapView,連接代理(我沒有創建任何方法,因爲我們實際上不需要做任何事情來觸發泄漏),鏈接到MapKit並啓動項目,然後在UISearchBar中單擊會導致1k +泄漏。除非在視圖中同時包含UISearchBar和MKMapView,否則不會發生這種情況。從代碼創建視圖時,我遇到同樣的問題。我認爲NIB的行爲可能不同,但事實並非如此。是MKMapView泄漏

是MKMapView泄漏,或者我做錯了什麼。

要使用的代碼複製問題試試下面的代碼 - 我創建了一個新的 「查看基於應用」 項目

TestMapViewFromCodeViewController.h

 
#import <UIKit/UIKit.h> 
#import <MapKit/MapKit.h> 

@interface TestMapViewFromCodeViewController : UIViewController { 
    UISearchBar *searchBar; 
    MKMapView *mapView; 

} 

@property (nonatomic, retain) MKMapView *mapView; 
@property (nonatomic, retain) UISearchBar *searchBar; 


@end 

TestMapViewFromCodeViewController.m

 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    UISearchBar * tmpSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0,0.0,self.view.frame.size.width,40.0)]; 
    [self.view addSubview:tmpSearchBar]; 
    [self setSearchBar:tmpSearchBar]; 
    [tmpSearchBar release]; 

    MKMapView *tmpMapView=[[MKMapView alloc] initWithFrame:CGRectMake(0.0,0.0,self.view.frame.size.width,self.view.frame.size.height)]; 
    tmpMapView.showsUserLocation=FALSE; 
    [self.view insertSubview:tmpMapView atIndex:0]; 
    [self setMapView:tmpMapView]; 
    [tmpMapView release]; 
} 


- (void)dealloc { 
    [mapView release]; 
    [searchBar release]; 
    [super dealloc]; 
} 

儘管我保留了s使用mapView和searchBar進行瀏覽,這可能不需要複製問題。

在此代碼發佈在此之前進行測試,我只注意到此泄漏不會發生在模擬器 - 只在我的手機......

+1

怎麼樣的代碼? 根據您對其他問題的自我回答,我認爲您應該查看SDK的內存管理指南。我知道當我開始使用iPhone時,由於我沒有垃圾收集器,我有一段時間泄漏了,因爲它已經有一段時間了。 – 2009-09-10 18:19:11

+0

無需代碼 - 只需將UISearchBar和MKMapView拖放到IB的視圖中即可。這就是複製它的必要條件。但是,當我在我的Mac前面時,我會挖掘代碼版本。上面發佈的代碼 – Andiih 2009-09-11 11:59:00

+0

。我也注意到這種泄漏只發生在我的設備上(不在模擬器中)。我還沒有更新iPhone操作系統版本,所以它仍然在3.0.1上。 – Andiih 2009-09-11 12:48:19

回答