Tag: 内存pipe理

内存泄漏与iPad中的大量图像

我试图在NSArray中存储UIImage数据,实际上是60个图像,每个大小为300kb。 然后,我试图在UIImageView中为图片添加animation。 我的代码: NSMutableArray *arr = [[NSMutableArray alloc] init]; for (int i=0; i<61; ++i) { [arr addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%i.png", i]]]; } img.animationImages = arr; img.animationDuration = 1.5; img.contentMode = UIViewContentModeBottomLeft; [img startAnimating]; 当我在iPad模拟器4.3testing它,它工作正常。 当我想在我的设备(iPad 1)上进行testing时,应用程序崩溃 。 注意:如果我注释下面的代码,应用程序不会崩溃: [img startAnimating]; 1.可能是什么问题? 我认为这是内存问题…? 2.我可以在NSArray中存储UIImage的Loooots吗?

将ViewController传递给子视图,然后再次返回,无法释放iOS中的VC

我有一个问题(与这个问题有关)。 但是根本问题与我原先想象的不同,我需要把它作为一个新的问题来发布。 但是我会更新上一个问题来引用这个问题 – 如果有人能够提供帮助的话。 我有一个UINavigationController ,它具有作为rootViewController 。 vcB然后被推到导航堆栈上。 vcB有一个子视图,它是一个UIView子类(称之为BSView ),上面有一些button。 我需要让vcB知道什么时候点击BSView上的button,所以我实现了一个@protocol就像在BBView.h一样,如下所示: @protocol BBViewDelegate <NSObject> @optional -(void)buttonAPressed; -(void)buttonBPressed; -(void)buttonCPressed; @end @interface BBView : UIView { id<BBViewDelegate> _delegate; NSString *_title; } – (id)initWithFrame:(CGRect)frame withTitle:(NSString *)title andDelegate:(id<BBViewDelegate>)delegate; @end 和BBView.m初始化方法如下所示: – (id)initWithFrame:(CGRect)frame withTitle:(NSString *)title andDelegate:(id<BBViewDelegate>)delegate { self = [super initWithFrame:frame]; if (self) { _delegate = delegate; _title = […]

MKMapView的内存使用率非常高

所以我有UIPageControl与UIPageControl有一堆MKMapViews(大多是15个不同的地图)的UIScrollView。 一旦这个视图加载,应用程序真的呆滞,几分钟后我得到一个内存警告。 我在“乐器”中看过,地图占用了一大笔记忆。 有时甚至高达200MB。 我能想到的一件事是重用mapViews。 但是,由于视图的结构如何,编码复杂度增加了。 任何build议如何我可以提高性能? 这是我的应用程序的结构: 我有一个视图控制器有一个UIScrollView我用于水平滚动。 在scrollView中,我从包含mkmapview的视图控制器数组中读取子视图。 希望这是有道理的! 我使用苹果的pageControl示例应用程序作为参考,而编码,所以devise大致相似。 提前致谢! 编辑:所以我试图添加mapView的单个实例和更改刷卡上的坐标。 它仍然需要大量的内存。

AFHTTPRequestOperations队列创build内存堆积

我刚刚更新到AFNetworking 2.0,我正在重写我的代码来下载数据并将其插入到Core Data中。 我下载JSON数据文件(从10到200MB的任何文件),将它们写入磁盘,然后将它们传递到后台线程来处理数据。 以下是下载JSON并将其写入磁盘的代码。 如果我只是让这个运行(甚至没有处理数据),应用程序使用内存,直到它被杀死。 我假设数据进入,它被存储在内存中,但是一旦我保存到磁盘,它为什么会留在内存中? 不应该autorelease池照顾这个? 我也设置了responseData和downloadData为零。 是否有明显的表明我在这里做错了? @autoreleasepool { for(int i = 1; i <= totalPages; i++) { NSString *path = …. NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:path]]; AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request]; op.responseSerializer =[AFJSONResponseSerializer serializer]; [op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { //convert dictionary to data NSData *downloadData = [NSKeyedArchiver archivedDataWithRootObject:responseObject]; […]

iPad应用程序在组合/合并两张图像时因内存警告而崩溃

我正在做image processing时,由于大量使用内存,我的应用程序崩溃。 基本上我的整个应用程序取决于下面的方法,其中用于组合图像的逻辑被用来从bundle中加载图像的另一种方法。 + (UIImage*)imageByCombiningImages:(UIImage*)firstImage withImage:(UIImage*)secondImage { @autoreleasepool { UIImage *image = nil; CGSize newImageSize = CGSizeMake(MAX(firstImage.size.width, secondImage.size.width), MAX(firstImage.size.height, secondImage.size.height)); if (UIGraphicsBeginImageContextWithOptions != NULL) { UIGraphicsBeginImageContextWithOptions(newImageSize, NO, [[UIScreen mainScreen] scale]); } else { UIGraphicsBeginImageContext(newImageSize); } [firstImage drawAtPoint:CGPointMake(roundf((newImageSize.width-firstImage.size.width)/2), roundf((newImageSize.height-firstImage.size.height)/2))]; firstImage =nil; [secondImage drawAtPoint:CGPointMake(roundf((newImageSize.width-secondImage.size.width)/2), roundf((newImageSize.height-secondImage.size.height)/2))]; secondImage=nil; image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } } – (UIImage*) getImage:(NSString*)imagename […]

在iOS内存问题的Sqlite

我花了几个小时试图解决这个问题,但我刚刚放弃了; 我不知道什么是错的。 在我的应用程序中,我执行嵌套的SQL操作来正确设置所有对象。 出于某种原因,有时sqlite3对象不能正确释放,导致内存上升。 我知道这是正确使用sql3_close和sql3_finalize的问题。 但是,正如你所看到的,我想我已经正确地使用了它们。 这是问题的根源: – (NSArray *) getAllSessions { if (sqlite3_open(dbPath, &db) == SQLITE_OK) { if (sqlite3_prepare_v2(db, query_stmt, -1, &statement, NULL) == SQLITE_OK) { while (sqlite3_step(statement) == SQLITE_ROW) { //I found out that doing something like that //toAdd.in_loc = [self getIndoorLocationWithId:[NSNumber numberWithInt:(int)sqlite3_column_int(statement, 6)]]; //messes the memory up all the time //but doing […]

ARC和释放在方法中创build的对象

我偶然发现了一个我在其他地方找不到答案的问题。 当我调用一个返回指向一个稍后使用的对象的指针的方法,并且在结尾设置为零时,它仍然被分配在内存中(根据Instruments)。 我正在使用XCode 4.6.3和iOS 6.1。 ARC打开。 这里是示例代码: ClassA.h @interface ClassA : NSObject -(void)runSomething; @end ClassA.m #import "ClassA.h" #import "ClassB.h" @implementation ClassA -(void)runSomething { int counter = 0; while (true) { ClassB *instance = [self makeClassBWithNumber:counter]; NSLog(@"%d", [instance getNumber]); [NSThread sleepForTimeInterval:0.01]; instance = nil; counter++; } } -(ClassB*) makeClassBWithNumber:(int)number { return [[ClassB alloc] initWithNumber:number]; } @end […]

NSZombieEnabled应该closures发布的应用程序或不?

随着NSZombieEnabled打开它将提供一些防范在运行时发生的EXC_BAD_ACCESS问题。 我正在做双重努力,以确保没有/less量内存泄漏,但我可能会释放,所以NSZombieEnabled打开将有助于防止这种情况,我是对的吗? 或者NSZombieEnabled打开,所有内存释放操作将被转换为无操作? 这将是一个大问题是这样的。

NSArray或NSMutableArray的removeAllObjects方法是否释放内存?

我需要知道NSArray或NSMutableArray的removeAllObjects方法是否释放内存。 如果我的数组有10000个元素。 我可以使用吗? [array removeAllObjects]; 释放内存并重新加载其他元素? 或者它泄漏内存? 谢谢 例如,如果我的NSMutable数组的大小为20mb,并带有10.000个元素,例如…如果我使用removeAllObjects方法…它的大小是0mb?

iOS上通过RTMP上的H264videostream

有一点挖掘,我已经find了一个库,从正在写入的.mp4文件中提取NAL单元。 我试图打包这个信息flv通过使用libavformat和libavcodec RTMP。 我使用以下方法设置videostream: -(void)setupVideoStream { int ret = 0; videoCodec = avcodec_find_decoder(STREAM_VIDEO_CODEC); if (videoCodec == nil) { NSLog(@"Could not find encoder %i", STREAM_VIDEO_CODEC); return; } videoStream = avformat_new_stream(oc, videoCodec); videoCodecContext = videoStream->codec; videoCodecContext->codec_type = AVMEDIA_TYPE_VIDEO; videoCodecContext->codec_id = STREAM_VIDEO_CODEC; videoCodecContext->pix_fmt = AV_PIX_FMT_YUV420P; videoCodecContext->profile = FF_PROFILE_H264_BASELINE; videoCodecContext->bit_rate = 512000; videoCodecContext->bit_rate_tolerance = 0; videoCodecContext->width = STREAM_WIDTH; videoCodecContext->height […]