【发布时间】:2011-01-31 02:01:34
【问题描述】:
大家! 我已经测试了这个最简单的代码如下:
StorePin.h
#import <Foundation/Foundation.h>
#import <MAPKIT/mapkit.h>
#import <CORELOCATION/corelocation.h>
@interface StorePin : NSObject <MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString *subtitle;
NSString *title;
}
@property (nonatomic,assign) CLLocationCoordinate2D coordinate;
@property (nonatomic,retain) NSString *subtitle;
@property (nonatomic,retain) NSString *title;
-(id) initWithCoords:(CLLocationCoordinate2D) coords;
@end
StorePin.m
#import "StorePin.h"
@implementation StorePin
@synthesize coordinate, subtitle, title;
- (id) initWithCoords:(CLLocationCoordinate2D) coords{
self = [super init];
if (self != nil) {
coordinate = coords;
}
return self;
}
- (void) dealloc
{
[title release];
[subtitle release];
[super dealloc];
}
@end
在我的 ViewController 中,我制作了一个按钮来重复添加和删除注释。
#import "mapViewTestViewController.h"
#import "StorePin.h"
@implementation mapViewTestViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (IBAction)refresh
{
[mapView removeAnnotations:mapView.annotations];
for (int i = 0; i < 101; i ++)
{
CLLocationCoordinate2D p1;
p1.latitude = i/10.0;
p1.longitude = i/10.0;
StorePin *poi = [[StorePin alloc] initWithCoords:p1];
[mapView addAnnotation:poi];
[poi release];
}
}
- (void)dealloc
{
[super dealloc];
}
@end
如果我循环添加和删除注释的次数少于 100 次,则一切正常。但是如果我循环超过100次,就会导致一次内存泄漏。我对这个奇怪的问题几乎疯了。这是我的代码的错误还是 mkmapview 的错误?谢谢你帮助我。
【问题讨论】:
标签: iphone memory-leaks annotations mkmapview