我的应用程序由于应用程序使用中某个点的内存压力而终止,我已将问题分解为造成问题的一大块代码.
我将复制下面的代码块,但首先我将描述它正在做什么.
描述:
我有一个迭代视频列表的for循环.对于每个视频,for循环增加包含滚动视图的大小,绘制标签和按钮(均与视频有关),并异步抓取视频的缩略图并将其放在按钮下方.
问题:
抓住缩略图部分就是问题所在.我不认为这是异步完成的事实是问题,因为我已经同步尝试并且终止仍然发生.当我注释掉抓取缩略图的代码(下面代码中的整个异步部分)时,应用程序不会崩溃.
守则:
注意:为简洁起见,我在某些情况下使用注释替换代码.
for (int i = [_videoURLs count]-1; i >= 0 ; i--)
{
//increase the scrollview size
//get background image:
dispatch_async(screenshotQueue, ^{
AVURLAsset *as = [[AVURLAsset alloc] initWithURL:currentURL options:nil];
AVAssetImageGenerator *ima = [[AVAssetImageGenerator alloc] initWithAsset:as];
ima.appliesPreferredTrackTransform = YES;
NSError *err = NULL;
CMTime time = CMTimeMake(1, 24);
CGImageRef imgRef = [ima copyCGImageAtTime:time actualTime:NULL error:&err];
UIImage *thumbnail = [[UIImage alloc] initWithCGImage:imgRef];
dispatch_async(dispatch_get_main_queue(), ^{
UIImageView *backgroundImage = [[UIImageView alloc]initWithFrame:buttonFrame];
backgroundImage.image = thumbnail; …Run Code Online (Sandbox Code Playgroud) 我在我的大项目中使用MKMapView.当我加载很多注释(超过700)并在MapKit上的这些点之间画线时,我收到xcode错误消息"由于内存错误而终止"并且应用程序崩溃.你可以在图像上看到:
.
我正在添加这样的行:

如果我的注释少于700,那么它的效果非常好.我在想它有一些记忆问题.我该如何解决这个问题呢?任何建议.
// adding annodation
for (int i=0; i<[fetcher.locations count]; i++)//fetcher.locations is NSMutableArray and inside have locationInfoClass objects . locationInfoClass is hold CLLocationCoordinate2D.
{
locationInfoClass * loc=[fetcher2.locations objectAtIndex:i];
CLLocationCoordinate2D coordinate1;
coordinate1.latitude = loc.lat;
coordinate1.longitude = loc.lon;
myAnnotation * ann = [[myAnnotation alloc] initWithCoordinate:annCoordinate title:@"uniqtitle" subtitle:@"uniqsubtitle"];
[mapView addAnnotation:ann];
}
#pragma mark -
#pragma mark -mapview overlay
CLLocationCoordinate2D *coordinates
= malloc(sizeof(CLLocationCoordinate2D) * [mapView.annotations count]);
for (int i=0; i<[mapView.annotations count]; i++) {
myAnnotation * ann=[mapView.annotations objectAtIndex:i];
coordinates[i]=ann.coordinate;
}
self.routeLine = [MKPolyline …Run Code Online (Sandbox Code Playgroud) 我正在开发一个ios 8自定义键盘扩展.它像一个魅力开始运行.
但我总是在Xcode中得到"接收内存警告".所以我的自定义键盘扩展有时会突然终止.
但我在其主机应用程序中运行自定义键盘.没有任何问题.不要在Xcode中获得"接收内存警告".不要终止.
有人可以帮帮我吗?如果app对扩展使用有任何限制大小?