【问题标题】:Releasing UIImage after use使用后释放 UIImage
【发布时间】:2010-09-22 11:24:36
【问题描述】:

我想学习分配 uiimage 并释放它以进行内存管理的正确方法。
当我使用以下代码时,它会在解除分配时崩溃,
如果我不使用 [成像器版本];
程序没有崩溃,但它显示成像仪泄漏。有什么解决办法吗?

UIImage *imager = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:s@"nameofimage" ofType:@"jpg"]];
UIImageView *imageView = [[UIImageView alloc] initWithImage:imager];

[imageView release];

[imager release];

【问题讨论】:

    标签: uiimageview uiimage release memory-leaks


    【解决方案1】:

    进行内存管理的正确方法就是你所做的。

    UIImage *imager = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"nameofimage" ofType:@"jpg"]]; 
    UIImageView *imageView = [[UIImageView alloc] initWithImage:imager];
    [imager release];
    [imageView release]; 
    

    如果你先发布 uiimage 而不是 uiimageview 可能会起作用

    我在这段代码中没有发现任何错误。如果应用程序崩溃,那么在它被释放后检查您是否在其他任何地方使用相同的对象引用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-24
      • 1970-01-01
      • 1970-01-01
      • 2014-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多