在我的应用程序中,我正在向我的应用程序加载一系列图像,这些图像UIImageView
是在init
Method上创建的
- (UIImage *)getImage:(int)currentIndex {
NSString *path = [self getImagePath:currentIndex];
[self.imageView setAccessibilityLabel:path];
path=[bundle pathForResource:path ofType:extension];
return [UIImage imageWithContentsOfFile:path] ;
}
- (void)changeImage:(int)currentIndex {
[self.imageView setImage:nil ];
[self.imageView setImage:[self getImage:currentIndex]];
}
但是这段代码会导致内存泄漏。比如
-malloc - 7KB - imageIO - png_malloc
我已经尝试使用适当的发布调用“[[UIImage alloc] initWithContentsOfFile]”,但仍然没有运气。
我在这里缺少什么。
大约全班
- (id)initWithFrame:(CGRect)frame andBundle:(NSBundle *) bundleTobeInjected {
self = [super initWithFrame:frame];
if (self) {
// Initialization code.
self.opaque = YES;
bundle=bundleTobeInjected;
commonFunctions=[[Common alloc] init];
self.imageView = [[UIImageView alloc] initWithFrame:frame] ;
[self.imageView setImage:nil ];
self.imageView.contentMode = self.contentMode;
[self addSubview:imageView];
[self setAccessibilityEnabled];
}
return self;
}
-(void)setAccessibilityEnabled
{
self.imageView.isAccessibilityElement=true;
}
#pragma mark - Custom Logic
- (NSString *)getImagePath:(int)currentIndex {
NSString *path = [NSString stringWithFormat:@"%@%d%@", prefix,currentIndex,[commonFunctions imageNamedSmartForRotationSuffix]];
NSLog(@"%@", path);
return path;
}
- (UIImage *)getImage:(int)currentIndex {
NSString *path = [self getImagePath:currentIndex];
[self.imageView setAccessibilityLabel:path];
path=[bundle pathForResource:path ofType:extension];
return [UIImage imageWithContentsOfFile:path] ;
}
-(void)changeImage:(int)currentIndex {
[self.imageView setImage:nil ];
[self.imageView setImage:[self getImage:currentIndex]];
}
-(void)dealloc{
[extension release];
[prefix release];
[defaultImage release];
[image release];
[imageView release];
[commonFunctions release];
[super dealloc];
}