objective-c - 分配的对象的潜在泄漏 - 不知道为什么
<p><p>有人可以帮我理解为什么静态分析器说在 for(NSDictionary...) 行存在潜在泄漏吗?</p>
<pre><code>- (void)imageSearchController:(id)searchController gotResults:(NSArray *)results
{
if ( == 0) {
UIAlertView *alertView = [[ initWithTitle:nil
message:@"I was not able to find anything! Please try again."
delegate:self cancelButtonTitle:@"OK"
otherButtonTitles:nil] autorelease];
;
} else {
;
for (NSDictionary *item in results) {
] retain]];
}
if (searchIndex <= 60) {
;
} else {
;
}
//position the images with respect to each other and screen orientation
;
}
;
}
- (void)clearImages
{
for (UIView *subview in ) {
if (] || ]) {
;
}
}
}
</code></pre>
<p>图像框将带有填充的图像返回给上述其他方法。自从我过去一直在使用 ARC 以来,我是内存管理的新手。如果您发现其他潜在的泄漏,请告诉我。我使用了泄漏仪器工具,它说没有泄漏!但我不确定情况是否如此,因为我试图引入泄漏,但它仍然说没有。以下是所有 ImageBox 代码:</p>
<pre><code>@interface ImageBox : UIView
@property (nonatomic, retain) UIImageView *imageView;
@property (nonatomic, retain) UIImage *image;
+ (id)createImageBoxWitImageURL:(NSString *)imageURL;
@end
@implementation ImageBox
@synthesize imageView;
@synthesize image;
- (id)initWithImageURL:(NSString *)imageURL
{
self = ;
if (self) {
int padding = 10;
int imageHeight = 108;
int imageWidth = 108;
int paddingBoxHeight = imageHeight + (2 * padding);
int paddingBoxWidth = imageWidth + (2 * padding);
NSData* imageData = [initWithContentsOfURL:];
image = [[ initWithData:imageData] autorelease];
;
imageView = [[ initWithImage:image] autorelease];
imageView.layer.masksToBounds = YES;
imageView.layer.cornerRadius = 13.0;
imageView.contentMode = UIViewContentModeScaleAspectFill;
CGRect imageFrame = CGRectMake(padding, padding, imageWidth, imageHeight);
;
CGRect paddingBoxFrame = CGRectMake(0, 0, paddingBoxWidth, paddingBoxHeight);
;
;
self.backgroundColor = ;
}
return self;
}
+ (id)createImageBoxWitImageURL:(NSString *)imageURL
{
ImageBox *imageBox = [ initWithImageURL:imageURL];
return ;
}
- (void)dealloc
{
;
;
;
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这是因为有一个明确的、不必要的<code>retain</code>。</p>
<pre><code>[imageGallery addSubview:
[] retain]];
^^^^^^
</code></pre></p>
<p style="font-size: 20px;">关于objective-c - 分配的对象的潜在泄漏 - 不知道为什么,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/10791656/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/10791656/
</a>
</p>
页:
[1]