Tag: 内存泄漏

为什么静态NSString泄漏?

我有以下代码来检索我的iOS应用程序的文件path: static const NSString * fullPathFromRelativePath(NSString *relPath) { // do not convert a path starting with '/' if(([relPath length] > 0) && ([relPath characterAtIndex:0] == '/')) return relPath; NSMutableArray *imagePathComponents = [NSMutableArray arrayWithArray:[relPath pathComponents]]; NSString *file = [imagePathComponents lastObject]; [imagePathComponents removeLastObject]; NSString *imageDirectory = [NSString pathWithComponents:imagePathComponents]; NSString *fullpath = [[NSBundle mainBundle] pathForResource:file ofType:NULL inDirectory:imageDirectory]; if […]

当类包含数组时,Swift 3枚举泄漏内存

我在Swift中发现了内存泄漏。 它给了我恶梦,因为我的代码到处都是小漏洞,然后我设法减less到这个小例子, import UIKit enum LeakingEnum { case LeakCase, AnotherLeakCase } class Primitive { var lightingType: LeakingEnum = .LeakCase var mysub : [Int] = [] init() { mysub.append(80) } } class ViewController: UIViewController { var prim: Primitive? override func viewDidLoad() { super.viewDidLoad() prim = Primitive() } } 如果你在iPhone上运行这个程序和configuration文件,你会发现在Array._copyToNewBuffer这个泄漏, 如果我删除对mysub.append的调用,它将停止泄漏。 如果我从Primitive删除枚举,它也会停止泄漏。 所有我有一个枚举泄漏这样的类。 什么发生在Swift枚举? Swift 3,Xcode 8.2.1和iOS […]

CoreImage的内存泄漏

我已经创build了如下的模糊图像: //Blur the UIImage CIImage *imageToBlur = [CIImage imageWithCGImage:viewImage.CGImage]; CIFilter *gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"]; [gaussianBlurFilter setValue:imageToBlur forKey: @"inputImage"]; [gaussianBlurFilter setValue:[NSNumber numberWithFloat: 2] forKey: @"inputRadius"]; CIImage *resultImage = [gaussianBlurFilter valueForKey: @"outputImage"]; CIImage *finalImage = [resultImage imageByCroppingToRect:CGRectMake(0, 10, self.view.bounds.size.width, self.view.bounds.size.height)]; //create UIImage from filtered image UIImage *blurrredImage = [[UIImage alloc] initWithCIImage:finalImage]; CIFilter *colorMatrixFilter = [CIFilter filterWithName:@"CIColorMatrix"]; […]

在IOS4.0中使用UIWebView加载请求时内存泄漏

我有一个Web视图作为模态视图加载。 我使用下面的代码加载网页后有内存泄漏。 [myView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30]]; 我的dealloc方法如下: – (void)dealloc { myView.delegate = nil; [myView release]; [url release]; [super dealloc]; } 仪器显示5块GeneralBlock 32泄漏,但没有可用的堆栈跟踪。 每次加载网页后都会发生泄漏,每次加载的时间恰好为5个块。 如果我在页面完全加载之前解除模态视图,则不会泄漏。 如果我将caching策略更改为NSURLRequestReturnCacheDataElseLoad泄漏仅在首次加载网页时发生。 我已经尝试了下面的链接方法,但它不适合我。 泄漏UIWebView 任何帮助表示赞赏。 谢谢。

目标C:ViewController中的GestureRecognizer – >保留周期?

我有一个我的ViewControllers(VC)的头文件中定义的以下属性: @property(nonatomic, retain) IBOutlet UIImageView *articleImageView1; 在VC的实现中,在方法viewDidLoad ,我将TapRecognizers附加到以下属性: UITapGestureRecognizer *captureImage1TapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self [self.articleImageView1 addGestureRecognizer:captureImage1TapRecognizer]; VC UIImageView 。 这个UIImageView是否也通过GestureRecognizer强有力地包含了VC? 这是一个保留周期的经典例子吗? 如果是这样,这是正确的解决scheme? -(void)viewDidUnload { … [self setArticleImageView1:nil]; … [super viewDidUnload]; }

存储在上下文中的对象的潜在泄漏

我得到这个代码的内存泄漏。 – (CGContextRef) createARGBBitmapContextFromImage:(CGImageRef) imageRef { CGContextRef context = NULL; CGColorSpaceRef colorSpace; void * bitmapData; int bitmapByteCount; int bitmapBytesPerRow; // Get image width, height. We'll use the entire image. size_t pixelsWide = CGImageGetWidth(imageRef); size_t pixelsHigh = CGImageGetHeight(imageRef); // Declare the number of bytes per row. Each pixel in the bitmap in this // example is […]

在子类中使用GKStateMachine泄漏

我会告诉你我的实际代码。 它有三个要素:帮手: import SpriteKit import GameplayKit class GameSceneHelper: SKScene { override func didMove(to view: SKView) { } } 具有某些游戏状态的助手的子类: import SpriteKit import GameplayKit class GameScene: GameSceneHelper { lazy var gameState:GKStateMachine = GKStateMachine(states: [ Introduction(scene: self), SecondState(scene: self) ]) override func didMove(to view: SKView) { self.gameState.enter(Introduction.self) } } 和国家。 在这里,我介绍其中之一。 另一个具有相同的结构: import SpriteKit import GameplayKit class […]

内存泄漏与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吗?

CoreImage / CoreVideo中的内存泄漏

我正在构build一个iOS应用程序,可以进行一些基本检测。 我从AVCaptureVideoDataOutput获取原始帧,将CMSampleBufferRef转换为UIImage,调整UIImage的大小,然后将其转换为CVPixelBufferRef。 至于我可以检测到仪器泄漏是我将CGImage转换为CVPixelBufferRef的最后一部分。 这是我使用的代码: – (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { videof = [[ASMotionDetect alloc] initWithSampleImage:[self resizeSampleBuffer:sampleBuffer]]; // ASMotionDetect is my class for detection and I use videof to calculate the movement } -(UIImage*)resizeSampleBuffer:(CMSampleBufferRef) sampleBuffer { UIImage *img; CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); CVPixelBufferLockBaseAddress(imageBuffer,0); // Lock the image buffer uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddressOfPlane(imageBuffer, 0); // […]

目标C:通过Xcode中的仪器检测泄漏

我在我的应用程序上运行的仪器,发现了一些泄漏,但是我不知道如何我可以破译的结果,例如我点击行'_NSArrayM' 之后,我点击了详细信息栏中的一个条目,显示以下内容, “100%”是什么意思?