English 中文(简体)
UIIMageViV 与 ARC 的内存泄漏
原标题:UIImageView memory leak with ARC

In detailView 主计长.h: @ property (弱、非原子) IBoutlet UIImaageView *recipeImaage; (弱、非原子) IBoutlet UIImage View *recipeImaage;

详细 VietView 主计长.m

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.recipeTitle.text = rec.title;
    self.recipeDetail.text = rec.details;
    NSString *fileName = [NSString stringWithFormat: @"%@/%@", [[NSBundle mainBundle] resourcePath], rec.image];
    UIImage *tmp = [[UIImage alloc] initWithContentsOfFile: fileName];
    self.recipeImage.image = tmp;
    NSLog(@"%@", rec.image);
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    recipeTitle = nil;
    recipeDetail = nil;
    recipeImage = nil;
    rec = nil;
}

出于某种原因 食谱图像 UIImage View IB 输出导致内存泄漏

""https://i.sstatic.net/R4FZN.png" alt="此处的内置图像描述"/ >

""https://i.sstatic.net/XsQbz.png" alt="此处输入图像描述"/ >

最佳回答

嗯,我对此感到有点惊讶,因为我看不到你的代码有任何明显的漏洞。所以我做了一个小测试项目(Xcode 4.3.2, iPhone模拟器5.1, ARC, 故事板),看看我是否能复制你的问题,然后通过描述器,然后,没有找到任何漏洞。

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    self.label1.text = @"Line 1";
    self.label2.text = @"Line 2";

    NSString *filename = [NSString stringWithFormat: @"%@/%@", [[NSBundle mainBundle] resourcePath], @"IMG_0999.PNG"];

    UIImage *image = [[UIImage alloc] initWithContentsOfFile:filename];

    self.image1.image = image;
}

和你一样,我使用弱的属性:

@property (weak, nonatomic) IBOutlet UILabel *label1;
@property (weak, nonatomic) IBOutlet UILabel *label2;
@property (weak, nonatomic) IBOutlet UIImageView *image1;

但我无法再重复你的问题。

令我惊讶的是,有一些合乎逻辑的可能性(这是一段延伸):首先,你的巴布亚新几内亚可能有什么独特之处吗?也许可以和我们分享一下,我可以试试我的测试。或者你可以试试其他的巴布亚新几内亚文件。或者你可以做我所做的,这是一个非常简单的项目,试图复制泄漏内容,看看在你的测试项目中你是否遇到同样的问题。第二,泄漏可能在你的代码中其他地方?我知道这些与民俗有关的泄漏对于指向你相关的代码是不好的,所以我想知道你是否有可能从别处泄露。

底线上,我试着复制你的问题,但不能。看起来可能需要进一步的诊断。

<强> 更新:

图像文件格式异常复杂,如果你查看PNG描述 ,你会看到一个十几个潜在的领域,iOS算法可能会漏出(或者因为iOS逻辑中的错误,或者因为PNG文件有问题) 。显然,它应该漏出,但显然iOS确实预知或处理对了某种调整。似乎值得。不管怎样,我建议打开并重新保存您所选的图形编辑器中的 PNG文件。有外部机会可以修正它。

问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签