Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 创建注释点时内存泄漏_Objective C - Fatal编程技术网

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第一个想法是正确的。我忘记在自定义注释中发布。谢谢发布一个解决方案,我将标记为正确。干杯