Objective c 创建注释点时内存泄漏
我在分析应用程序时发现内存泄漏Objective c 创建注释点时内存泄漏,objective-c,Objective C,我在分析应用程序时发现内存泄漏 CustomAnnotation *annotationPoint = [[CustomAnnotation alloc] initWithLatitude:store.latitude longitude:store.longitude]; annotationPoint.titleLabel = store.name; annotationPoint.subtitleLabel = [NSString stringWithFormat:@"%dm", sto
CustomAnnotation *annotationPoint = [[CustomAnnotation alloc] initWithLatitude:store.latitude longitude:store.longitude];
annotationPoint.titleLabel = store.name;
annotationPoint.subtitleLabel = [NSString stringWithFormat:@"%dm", store.distance];
[annotationPoint setEvent:store];
[self.mapView addAnnotation:annotationPoint];
[annotationPoint release];
这是指定为泄漏和注释点的内容。subtitleLabel=[NSString stringWithFormat:@%dm,store.distance];标记为100%
我应该怎么做才能解决这个问题?您是否在CustomAnnotation的dealoc函数中调用[subtitleLabel release]? 在这种情况下,这将解决问题,但是 如上所述:[NSString stringWithFormat]返回一个自动删除的对象。
这意味着您必须使用autoreleasepools进行正确的内存管理。您是否在自定义批注的dealloc函数中调用[subtitleLabel release]?属性是如何定义的?分配是否保留?[NSString stringWithFormat]由NSString自动删除。如果没有自动释放池,则NSString正在泄漏。@guitarflow第一个想法是正确的。我忘记在自定义注释中发布。谢谢发布一个解决方案,我将标记为正确。干杯