Tag: 内存pipe理

如何提高iPad应用程序的内存占用

我有一个iPad的应用程序做得非常好,5个月和3个发布后,苹果报告零坠毁。 然而,偶尔操作系统杀死应用程序,我的猜测是缺乏可用内存。 我在警告低调事件中没有做任何事情。 我想收到一些我应该做的改进内存占用的可靠build议。 我可以开始使用哪些工具和技巧来了解我现在的位置,以及我可以如何进一步改进。

加载UIImage的好习惯

我在我的应用程序中有几个图标,我在多个视图中重用(例如最喜欢的图标)。 为了节省内存,我想知道是否使用类加载静态图像的类方法是一个好主意? 例如 : + (UIImage *)favoriteIcon { static UIImage * icon; if (!icon) icon = [UIImage imageNamed:@"favorite.png"]; return icon; } 或者我应该每次需要时只使用+ (UIImage *) imageNamed:(NSString *)name ? 感谢您的build议。

使用AFNetworking下载文件时的内存警告

更新: 我写了一个非常简单的下载代码: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSURLRequest* request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://xxxx.s3.amazonaws.com/products/ipad/xxxx.mp4"]]; for(int i=0; i<4; i++){ NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,[NSString stringWithFormat:@"xxxx%d.mp4",i]]; AFDownloadRequestOperation* operation = [[AFDownloadRequestOperation alloc] initWithRequest:request targetPath:filePath shouldResume:YES]; operation.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:NO]; [operation setShouldOverwrite:YES]; [operation setProgressiveDownloadProgressBlock:^(AFDownloadRequestOperation *operation, NSInteger bytesRead, long long totalBytesRead, long […]

EXC_BAD_ACCESS和NSFetchedResultsController

试图追踪这个错误,当我有NSZombieEnabled 。 当获取的结果控制器尝试执行提取时,我得到一个EXC_BAD_ACCESS。 debugging器说: -[CFNumber retain]: message sent to deallocated instance 0x6e88d10 Backtrace说: #0 0x014bbe1e in ___forwarding___ () #1 0x014bbce2 in __forwarding_prep_0___ () #2 0x0145c490 in CFRetain () #3 0x0147929a in CFNumberCreate () #4 0x00b221ed in -[NSPlaceholderNumber initWithShort:] () #5 0x00b2216a in +[NSNumber numberWithShort:] () #6 0x010a549e in snapshot_get_value_as_object () #7 0x010a2a41 in _sharedIMPL_pvfk_core () […]

驻留内存与活动字节

假设:我正在使用Cocos2d 2.0和ARC(以及使用XCode 4.5.2的仪器)的iPhone项目。 简单的问题:为什么常驻内存比活字节多得多? 我这样说是因为: 使用工具:我得到低内存警告,我运行我的分配工具,并查看平均3/5 MB的实时字节。 然后我得到一个高峰(18MB),然后回到3 / 5MB。 问题是,每当我不停地从一个场景前进到另一个场景时,我会得到低内存警告。 使用驻留内存控制台打印 – (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { [self report_memory]; [[CCDirector sharedDirector] purgeCachedData]; } -(void) report_memory { struct task_basic_info info; mach_msg_type_number_t size = sizeof(info); kern_return_t kerr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &size); if( kerr == KERN_SUCCESS ) { NSLog(@"Memory in use (in bytes): %u", info.resident_size); } else { […]

将iOS应用程序移植到mac – 如何处理内存pipe理?

我的代码当然有所有的保留/释放调用。 。 。 是否可能更容易与垃圾收集编写mac应用程序(然后我怎么做的保留/释放)或没有? 无论您推荐哪种方式,任何有关Xcode设置的指针都会有所帮助。 谢谢。

NSMutableArray访问问题

我(想)我知道你在想什么…不是另一个EXC_BAD_ACCESS问题,但我真的很挣扎,这让我疯狂。 我在网上search了很多,在这里,我面临的问题似乎与我的memory management有关。 问题: 基本上我有一个NSMutableArray ,跟踪一些networking食物。 由于食物可以在同一时间被添加和拿走,所以我有一个单独的数组,用于检查要移除的物品,并保存那些不需要取出的物品。 这个想法是清除原始数组( _food ),并将临时数组( foodToKeep )中保存的所有项目复制回来。 这是代码 NSMutableArray *foodToKeep = [[NSMutableArray alloc] init]; for (Food *food in _food) { if(!food.removeable){ [foodToKeep addObject:food]; [food release]; } } if(foodToKeep > 0){ [_food removeAllObjects]; for (Food *food in foodToKeep) { [_food addObject:food]; // EXC_BAD_ACCESS error here [food release]; } } } [foodToKeep […]

需要关于UIViewController的帮助

在多个UIViewController一起工作的应用程序中, firstViewController添加到根。 直到现在它罚款现在我想去secondViewController我不想使用UINavigationController或UITabBarController 。 我已经阅读了“ 视图控制器编程指南”,但没有使用UINavigationController, UITabBarController and story board 。 当用户想从secondViewController移动到firstViewController如何secondViewController将被销毁? 苹果文件也不指定UIViewController如何释放或销毁? 它只是告诉UIViewController里面的生命周期。

iOS – 一次不分配太多的内存

试图绕过一些iOS设备上发生的崩溃,并结合苹果的build议“不会导致分配高峰”。 我怎样才能改变这个代码不会一次发生? for (Item *item in self.items) { ItemView *itemView = [[ItemView alloc] initWithFrame:CGRectMake(xPos, kYItemOffsetIphone, kItemWidthIphone, kItemHeightIphone) ]; itemView.delegate = self; [itemView layoutWithData:item]; //this just adds an imageView and button [self.scrollView addSubview:itemView]; xPos += kXItemSpacingIphone; } self.items数组中有大约20个对象,用于构build20个ItemView。 再一次,有没有办法让这个代码更“分配密集”?

展开segue不会释放我的视图控制器

我有这样的东西: 我的rootViewController是一个navigationBar – 让这是A.剩下的是正常的UIViewControllers ,并通过推(通过buttonIBAction方法)编程方式继续。 但是从D – > A,我使用unwind segue(也通过performSegueWithIdentifier:sender :)。 这里的问题是当执行segue时,B,C和D根本就不被deallocated 。 这不仅导致内存泄漏问题,但我的计时器仍在运行。 我不确定为什么是这样。 我认为放松的赛段是想为你处理所有这些? 任何想法为什么?