【发布时间】:2011-04-03 23:48:59
【问题描述】:
我有一个带有非常大图像的 IntroViewController,这使我的应用程序的内存增加了大约 1.5MB。图像设置在 View Controller 的 NIB 中的 UIImageView 上。
介绍完成后,我在 IntroViewController 上调用 release,然后它在自身上成功调用 dealloc 并在大型 UIImageView 上调用 release。然而,我在 Instruments 中的记忆似乎并没有再次下降。我可以通过简单地将图像重命名为NIB中的UIImageView来测试内存差异,这样它就找不到任何东西了,然后内存下降了大约1.5MB。
那为什么我没有找回记忆呢?有什么我遗漏的东西阻止了 UIImageView 被正确地释放吗?
谢谢,
:-乔
------- 添加:代码 ------
#import <UIKit/UIKit.h>
@class AppDelegate_iPhone;
@interface IntroViewController : UIViewController
{
AppDelegate_iPhone *appDelegate;
UIImageView *wheelImageView;
UIView *copyOverlayView;
}
@property (nonatomic, retain) IBOutlet UIImageView *wheelImageView;
@property (nonatomic, retain) IBOutlet UIView *copyOverlayView;
- (void)startAnimation;
@end
@implementation IntroViewController
@synthesize wheelImageView, copyOverlayView;
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate = (AppDelegate_iPhone *)[[UIApplication sharedApplication] delegate];
[self startAnimation];
}
- (void)viewDidDisappear:(BOOL)animated
{
[self.wheelImageView removeFromSuperview];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.wheelImageView.image = nil;
appDelegate = nil;
}
- (void)dealloc
{
[wheelImageView release];
[copyOverlayView release];
[super dealloc];
}
- (void)startAnimation
{
self.wheelImageView.transform = CGAffineTransformMakeScale(0.5, 0.5);
[UIView beginAnimations:@"wheelScale" context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(wheelScaleDidFinish)];
self.wheelImageView.transform = CGAffineTransformMakeScale(1.0, 1.0);
[UIView commitAnimations];
[UIView beginAnimations:@"copyOverlayFade" context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationDelay:1.0];
self.copyOverlayView.alpha = 0;
[UIView commitAnimations];
}
- (void)wheelScaleDidFinish
{
[appDelegate introAnimationFinished];
}
@end
---- 编辑
有人可以帮忙吗?我被难住了,这导致我的应用程序由于内存过高而在 iPhone 上崩溃 :( 无法弄清楚如何摆脱愚蠢的图像!Grrrr ...
【问题讨论】:
标签: objective-c iphone memory-management memory-leaks