每次进入同一视图时,内存都会增加。即使我没有发布任何信息,由于较旧的应用程序问题,我也无法使用ARC。不知道如何解决这个问题。
#import <UIKit/UIKit.h>
#import "CareServices.h"
@interface AttachedImage : UIViewController<ServerConnectionDelegate,UIScrollViewDelegate>
{
IBOutlet UIImageView *imageView;
CareServices *careServices;
UIScrollView *_scrollView;
UIView *activityView;
UIActivityIndicatorView *_activity;
}
@property (nonatomic,retain)UIImageView *imageView;
@end
#import "AttachedImage.h"
#import"XMLParserForOtherAttachments.h"
#import "ColorSchemes.h"
@implementation AttachedImage
@synthesize imageView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
activityView = [[UIView alloc]initWithFrame:CGRectMake(self.view.frame.size.width/2.5,self.view.frame.size.height/2.5, 60, 60)];
activityView.backgroundColor = [UIColor clearColor];
[self.view addSubview:activityView];
UIImageView *activityImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, activityView.frame.size.width, activityView.frame.size.height)];
activityImageView.image = [UIImage imageNamed:@"indicatorImage.jpeg"];
[activityView addSubview:activityImageView];
[activityImageView release];
_activity = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[_activity setFrame:CGRectMake(activityView.frame.size.width/5.8, activityView.frame.size.height/5.3, 40, 40)];
[activityView addSubview:_activity];
[_activity startAnimating];
[_activity release];
careServices = [CareServices currentInstance];
careServices.delegate = self;
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[super viewDidLoad];
self.navigationItem.title = @"Attachment View";
// self.view.backgroundColor = [ColorSchemes sharedInstance].primaryColor1;
self.view.backgroundColor = [UIColor blackColor];;
// Do any additional setup after loading the view from its nib.
}
-(void)viewDidAppear:(BOOL)animated {
NSString *senderTagStr;
NSUserDefaults *senderD = [NSUserDefaults standardUserDefaults];
senderTagStr = [senderD valueForKey:@"sender tag"];
_scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
_scrollView.maximumZoomScale = 4.0;
_scrollView.minimumZoomScale = 1.0;
_scrollView.delegate = self;
_scrollView.contentSize = CGSizeMake(400, 500);
if (careServices.loginMode == ELoginModeDemo) {
if ([senderTagStr isEqualToString:@"0"]) {
imageView.image = [UIImage imageNamed:@"R1.bmp"];
}
else {
imageView.image = [UIImage imageNamed:@"8.jpg"];
}
}
else {
NSString *str = [NSString stringWithString:[XMLParserForOtherAttachments sharedManager].fileURlStr];
NSString *trimmedStr = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSData *imgData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:trimmedStr]];
UIImage *myImage = [UIImage imageWithData:imgData];
imageView.image = myImage;
[imgData release];
}
[_scrollView addSubview:imageView];
[self.view addSubview:_scrollView];
[_activity stopAnimating];
[activityView removeFromSuperview];
}
- (void)viewDidUnload {
[[NSURLCache sharedURLCache] removeAllCachedResponses];
self.imageView = nil;
[super viewDidUnload];
}
- (void)dealloc{
[imageView release];
[super dealloc];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return imageView;
}
@end
最佳答案
一旦您learn to use Heapshot Analysis,找到有问题的分配/实现就很容易了。
Heapshot Analysis允许您在执行期间拍摄快照,以检测一段时间内的增长,当然,在许多情况下,您可以将其与用户操作相关联。因此,例如您可以将视图控制器推入iOS的导航堆栈中,然后退后一步并轻松确定这样做的增长点。然后导航到导致增长的实现。
关于ios - 每当我进入此 View 时,内存都会增加,并且在此代码中无法使用arc,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13247100/