Tag: 内存泄漏

OpenCV MatToUIImage导致内存泄漏

我的项目正在与iOS的openCV(2.4.9)。 我发现MatToUIImage函数会导致内存泄漏,只发生在iOS 10.X上。 在我更新这个函数(2.4.9)到最新的(3.2.0)版本之后,所有的东西都得到了工作。 唯一的区别是CGBitmapInfo 。 那么有谁能告诉我为什么? 2.4.9 UIImage* MatToUIImage(const cv::Mat& image) { NSData *data = [NSData dataWithBytes:image.data length:image.elemSize()*image.total()]; CGColorSpaceRef colorSpace; if (image.elemSize() == 1) { colorSpace = CGColorSpaceCreateDeviceGray(); } else { colorSpace = CGColorSpaceCreateDeviceRGB(); } CGDataProviderRef provider = CGDataProviderCreateWithCFData((__bridge CFDataRef)data); // Creating CGImage from cv::Mat CGImageRef imageRef = CGImageCreate(image.cols, image.rows, 8, 8 * image.elemSize(), […]

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

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

iPhone / iPad的IOS应用程序仪器内存计数与task_info内存计数

我一直在使用仪器泄漏testing仪,它给总分配一个1-3兆左右的应用程序的数字。 但是,使用task_info时,它会报告更大的内存量,如10-20兆。 我想我只是想确认task_info正在返回某种types的内存,包括堆栈/ etc,其中泄漏testing器只报告Malloc / Alloc内存。 另外,为什么在应用程序中,当泄漏testing程序没有增加那么多的时候,task_info数字会增加很多…. 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 { NSLog(@"Error with task_info(): %s", mach_error_string(kerr)); }

内存泄漏.showsPhysics

我最近花了5个小时试图debugging我的Spritekit应用程序中的内存泄漏。 应用程序启动后,我注意到我的内存使用情况的一个小爬。 我花了5个小时中的3个,通过参考材料挖掘,了解强VS VS弱(绝对推荐阅读中间体,如我自己) 有没有人遇到这个问题? 如果有,有什么解释? 这里是我的GameViewController的一个小片段: class GameViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() if let scene = MainMenu(fileNamed:"MainMenu") { // Configure the view. let skView = self.view as! SKView skView.showsFPS = true skView.showsNodeCount = true skView.multipleTouchEnabled = true skView.showsPhysics = true /* Sprite Kit applies additional optimizations to improve rendering performance */ […]

Swift 2:IBOutlet Collection ! 泄漏内存

最近在我的应用程序中,我发现我的UIButtonsockets集合正在泄漏内存。 我所拥有的就是 @IBOutlet var TabBarButtons: [UIButton]! 从仪器 谁能告诉我出了什么问题? 随着时间的推移,NSArray中variables的数量不断增长,我所拥有的是一个包含4个来自IB的UIButton的数组。

滚动UICollectionView使用大量的内存导致崩溃

我正在开发一个表情符号键盘。 这是我的做法: 我决定使用UICollectionView。 我在代码中做所有事情,不打算使用Xib文件。 我创build了UICollectionViewCell的一个子类。 这将包含一个显示表情符号的标签。 这是我在initWithFrame里面做的 – (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { if (_label == nil) { _label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)]; _label.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); _label.textAlignment = NSTextAlignmentCenter; [_label setNumberOfLines:1]; self.contentView.layer.cornerRadius = 6.0; [self.contentView addSubview:_label]; } } return self; } 在UICollectionView dataSource对象中,我读取一个plist文件,其中包含一个NSDictionary,NSString为键,NSArrays为值。 在每个NSArray内,可以find我要展示的表情符号。 然后我把这本字典存放在一个属性中。 这里是代码: […]

在使用UIImagePickerControllerOriginalImage从UIImagePickerController获取图像时获取内存警告

我正在使用UIImagePickerController从相机获取图像。 刚刚捕捉图像,并获取它通过使用UIImagePickerControllerOriginalImage获取内存警告。 我在iOS上使用iphone 4s。 代码在这里 – (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [self dismissViewControllerAnimated:YES completion:nil]; UIImage* originalImage = [info objectForKey:UIImagePickerControllerOriginalImage]; //Getting memory warning after this line NSData *data =UIImageJPEGRepresentation(originalImage, 0.1); }

NSURLSession HTTP / 2内存泄漏

这个我的testing案例,指出当使用NSURLSession与HTTP / 2连接时有内存问题。 test1:iOS 9. HTTP / 2服务器 我使用NSURLSession将10Mfile upload到HTTP / 2服务器,如果上传的文件一切正常,但是如果我在上传任务完成之前取消上传任务,那么10M永远不会释放。 test2:iOS 9. HTTPs1.1服务器 我用https1.1文件服务器testing了相同的代码,我取消了上传任务,一切正常,内存恢复正常(10M数据发布) test3 iOS 8. HTTP / 2服务器 这种情况一切正常(NSURLSession没有与HTTP / 2协议协商) 所以,即使有一些不适合我的使用NSURLSession,NSURLSession的性能与HTTP / 2不正常。 除了内存问题之外,当使用NSURLSession和HTTP / 2来上传文件时,进度段的大小是巨大的(一次callback5月2日“didSendBodyData” 我也读过这个页面 。 SSL可能caching一些东西,但不应该caching整个文件(当我取消任务或请求超时,10M文件大小的内存泄漏) 任何人知道是什么原因造成的问题,可以给我一些帮助。 谢谢。 问题更新0912:添加testing项目链接 testing项目: https : //github.com/upyun/swift-sdk/tree/testleak file:UPUtils.swift //Change the url to make comparison test. //let DEFAULT_UPYUN_FORM_API_DOMAIN = "http://v0.api.upyun.com"//http1.1 //let DEFAULT_UPYUN_FORM_API_DOMAIN […]

存储在对象中的潜在的泄漏

我正在分析这个来自SDK的代码块,并根据我最近的问题的答案, 如何在iOS中正确释放内存:内存永远不会释放; 潜在的内存泄漏 dasblinkenlightbuild议我创build一个NSData对象可以释放我的uint8_t *字节… 但是在这个代码中: /** * this will set the brush texture for this view * by generating a default UIImage. the image is a * 20px radius circle with a feathered edge */ -(void) createDefaultBrushTexture{ UIGraphicsBeginImageContext(CGSizeMake(64, 64)); CGContextRef defBrushTextureContext = UIGraphicsGetCurrentContext(); UIGraphicsPushContext(defBrushTextureContext); size_t num_locations = 3; CGFloat locations[3] = { 0.0, 0.8, […]

UIGraphicsGetImageFromCurrentImageContext() – 内存泄漏

我用UIImagePickerControllerSourceTypeCamera和一个自定义cameraOverlayView打开相机,这样我就可以在不使用“使用照片”步骤的情况下拍摄多张照片。 这工作得很好,但保存照片function有一个内存泄漏。 通过大量的debugging和研究,我将其缩小到了UIGraphicsGetImageFromCurrentImageContext函数。 这是一个代码片段,它发生的地方: UIGraphicsBeginImageContextWithOptions(timestampedImage.frame.size, timestampedImage.opaque, [[UIScreen mainScreen] scale]); [[timestampedImage layer] renderInContext:UIGraphicsGetCurrentContext()]; UIImage *finalTimestampImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 我已经search了互联网,似乎UIGraphicsGetImageFromCurrentImageContext()函数(从这个SO问题引用) “返回一个新的自动释放的UIImage并指向它的最后finalTimestampImage伊娃。以前分配的UIImage是从来没有实际释放,它的variables只是被指派到别的地方。“ 我已经尝试了很多显然为别人工作的解决scheme: 添加timestampedImage.layer.contents = nil; 在UIGraphicsEndImageContext之后 添加CGContextRef context = UIGraphicsGetCurrentContext(); 和CGContextRelease(context); 在UIGraphicsEndImageContext之后 用NSAutoreleasePool包装上面的代码片段 将整个saveThisPhoto函数包装在一个NSAutoreleasePool 当相机popup并调用NSAutoreleasePool时调用[pool release]时创build一个NSAutoreleasePool 当didReceiveMemoryWarning被调用时closures相机popup,希望它会清除池 以上所有可能的组合 然而,我所尝试的一切,当我拍照时,我可以看到Memory Utilized上升,而不是在我反复在设备上拍照时不下降。 有谁知道我可以释放由UIGraphicsGetImageFromCurrentImageContext创build的autorelease对象吗? 另外,是否有一种替代方法来使UIImageView的UIImage ? 编辑: 以下是所要求的全部function。 有很多额外的释放,只是为了确保一切都被清理。 我已经通过系统地testing了saveThisPhoto每个代码块的内存泄漏,并且只有在UIGraphicsGetImageFromCurrentImageContext块(上面的代码片段)运行时才会发生。 – (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSLog(@"SAVING PHOTO"); [self saveThisPhoto:info]; […]