Tag: 内存

大量内存消耗:ImageIO_jpeg_Data

我有一个TableViewController显示一个用户的图像和一些文本每行的条目。 这个图像加载在“cellForRowAtIndexPath”方法中: func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { var cell : ApplicantsCell = tableView.dequeueReusableCellWithIdentifier("Cell") as! ApplicantsCell {…} let image = UIImage(named: "avatar") cell.applicantImage.image = image if let applImage = applicant.image as PFFile? { applImage.getDataInBackgroundWithBlock { (imageData: NSData?, error: NSError?) -> Void in if error == nil { let image = UIImage(data: imageData!) […]

iOS-CVPixelBuffer创build内存无法正确释放时,图像到video

我正在把图像制作成video。 但总是因为内存警告而崩溃,CVPixelBufferCreate上分配太多。 不知道如何处理它的权利。 我见过很多类似的话题,没有一个能够解决我的问题。 这是我的代码: – (void) writeImagesArray:(NSArray*)array asMovie:(NSString*)path { NSError *error = nil; UIImage *first = [array objectAtIndex:0]; CGSize frameSize = first.size; AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL: [NSURL fileURLWithPath:path] fileType:AVFileTypeQuickTimeMovie error:&error]; NSParameterAssert(videoWriter); NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys: AVVideoCodecH264, AVVideoCodecKey, [NSNumber numberWithDouble:frameSize.width],AVVideoWidthKey, [NSNumber numberWithDouble:frameSize.height], AVVideoHeightKey, nil]; AVAssetWriterInput* writerInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings]; self.adaptor = […]

iOS – 我的应用程序崩溃与内存错误,如果只在设备上运行

我的应用程序在模拟器上运行完美。 但是当我在设备上运行它来testing,应用程序崩溃。 显示的错误: “对象0x17415d0c0的malloc:*错误:从空闲列表中出列的无效指针*在malloc_error_break中设置断点以进行debugging”; 而另一个错误有时会发生: “线程6 com.apple.NSURLConnectionLoader:编程接收信号:EXC_BAD_ACCESS” 这两个错误是随机的,它发生在应用程序运行两三分钟后。 我search了Google并find了一些解决scheme。 它说,在malloc_error_break中设置一个断点来debugging,但这只能在模拟器上工作。 即使我设置malloc_error_break,应用程序仍然暗恋,它不显示任何东西,我只能看到该错误信息。 这是一个大项目,我真的不知道哪部分代码会导致问题,以及我需要发布哪部分代码。 但是我对课堂上的一个人,我的'SynchroningView'有疑问。 这个视图将显示,如果只有我的应用程序与服务器进行同步。 这意味着这个视图几乎包含在我的项目中的所有ViewController中。 这是我的'SynchroningView'类: “SynchroningView.h” #import <UIKit/UIKit.h> @class SynchroningView; @protocol SynchroningViewDelegate @optional – (void)SynchroningViewCancelButtonDidClicked:(SynchroningView *)synchroningView; – (void)SynchroningViewStartTherapyButtonDidClicked:(SynchroningView *)synchroningView; @end @interface SynchroningView : UIView <DataManagerDelegate> @property (nonatomic, assign) id<SynchroningViewDelegate>delegateCustom; @property (nonatomic, retain) UIButton *containerButton; @property (nonatomic, retain) Patient *singlePatient; – (instancetype)initWithFrame:(CGRect)frame; – (void)showInView:(UIView *)view; […]

核心文本内存分配问题

我用分配工具检查了我的应用程序,发现这个代码在这里给我一个分配问题。 该方法返回填充了通过的属性string的平方区域的build议高度; 我需要这个来计算需要多less空间来绘制文本然后生成书页: – (CGFloat)boundingHeightForWidth:(CGFloat)inWidth ForAttributedString:(NSAttributedString *)attributedString { CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((__bridge CFMutableAttributedStringRef)attributedString); CGSize suggestedSize = CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRangeMake(0, 0), NULL, CGSizeMake(inWidth, 10000), NULL); CFRelease(framesetter); return suggestedSize.height ; } 由于我在这个stream程中多次调用这个方法,我想知道这是如何导致高达7MB的内存分配..我认为释放帧设置可能是足够的,我错了吗?

将imageNamed转换为imageWithContentsOfFile:

我的代码为我的图像是 -(IBAction)start:(id)sender { animation.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"Paddle 1.png"], [UIImage imageNamed:@"Paddle 2.png"], [UIImage imageNamed:@"Paddle 3.png"], [UIImage imageNamed:@"Paddle 4.png"], nil]; [animation setAnimationRepeatCount:0]; animation.animationDuration = 2.5; [animation startAnimating]; } 这是caching太多的内存,我在前面的问题被告知交换我的代码使用 [UIImage imageWithContentsOfFile: GetImgWithoutCaching(@"Paddle 1.jpg")] 和 UIImage* GetImgWithoutCaching(NSString* imgName) { NSString *imagePath = [[NSBundle mainBundle] pathForResource:imgName ofType:nil]; return [UIImage imageWithContentsOfFile:imagePath]; } 编写代码的正确方法是什么? 我是否将该代码放在我的.m中?

在NSTimer中调用AFNetworking会导致严重的内存泄漏

我试图debugging一个困难的内存泄漏。 在MyAppDelegate.m中,我有 – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.notificationTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(syncNotifications:) userInfo:nil repeats:YES]; return YES; } – (void)syncNotifications:(NSTimer*)timer { NSString *path = @"http://example"; NSLog(@"GET: %@", path); AFHTTPRequestOperationManager *network = [AFHTTPRequestOperationManager manager]; [network GET:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"get success"); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }]; } […]

在UINavigationController中释放ViewControllers的内存

我正在使用UINavigationController构build应用程序。 我有一个ViewController显示一些内容,当它从用户接收交互(例如点击一个button)时,显示一个新的ViewController 。 这里是代码: FirstViewController.m -(IBAction)goToSecondVC:(id)sender{ SecondViewController *secondVC = [[SecondViewController alloc] init]; [self.navigationController pushViewController: secondVC]; } 一旦SecondViewController出现,我想从内存中释放FirstViewController 。 然后,例如,如果我从SecondViewController跳转到FifthViewController我也希望SecondViewController被释放。 当我在控制器之间来回跳转时,应用程序消耗的内存会增加,这意味着它们不会被释放。 有什么想法吗? 当我在控制器之间切换时,内存指示器会发生这种情况。 ARC被激活:

不知道是否是内存泄漏(ARC)

我正在写自定义animation,我怀疑我有一个内存泄漏,但我不知道。 每次我运行一个给定的animation时,内存都会上升一点,但是不会下降。 为了确定,我做了一个testing: NSLog(@"%@", self.weakanim); // The animation collection to run HyAnimationCollection * collection = [[HyAnimationCollection alloc] init]; self.weakanim = collection; 首先这个日志nillogging,那么它总是logging一个地址。 所以这里有两个指标: 内存从9.7MB开始,每10次运行一次就增加0.1MB。 我testing了这个大约12MB。 现在,每次释放内存还是仅仅是ARC(就像JVM的垃圾收集器)只是周期性地释放内存? 也就是说,也许这不是泄漏,而是ARC还没有释放它,因为我没有达到一定的数量。 为了看看之前的animation片集是否被释放,我宣称weakanim weak ,但同样的问题仍然存在:ARC是不是还没有发布呢 ?

应用程序在dealloc崩溃

我的应用程序在dealloc崩溃,但只是有时。 我创build了一个caching5个对象的数组。 当用户点击右键或左键时,会添加一个新对象,最后一个被删除。 当我testing应用程序时,点击右侧或左侧button100-500次,应用程序崩溃。 该应用程序在dealloc方法崩溃,但所有的对象分配和正确释放。 我的dealloc方法: – (void)dealloc { [super dealloc]; [_sImageLane release]; [_sTipoLane release]; [_maRecomended release]; [_maProdcucts release]; // here crash in this line EXC_BAD_ACCESSE } 出了什么问题?

Swift iOS:使用以下代码泄漏内存(video播放器)

我用游戏中的永久循环播放全屏video(用于背景)。 它工作的很好,但是当我改变视图时,我得到这个代码上的Instruments(内存泄漏模板)标识的内存泄漏: urlStr = NSBundle.mainBundle().pathForResource("Video_Socle", ofType: "mov") let url = NSURL(fileURLWithPath: urlStr!) player = AVPlayer(URL: url) NSNotificationCenter.defaultCenter().addObserverForName(AVPlayerItemDidPlayToEndTimeNotification, object: player!.currentItem, queue: nil) { notification in let t1 = CMTimeMake(5, 100); self.player!.seekToTime(t1) self.player!.play() } videoNode = SKVideoNode(AVPlayer: player!) videoNode!.anchorPoint = CGPointMake (0,0) videoNode!.size = CGSize(width: 2048, height: 1536) videoNode!.zPosition = 0 background.addChild(videoNode!) if synch == false { […]