1

每次我进入相同的视图内存都在增加。即使我发布什么也没发生,由于较旧的应用程序问题,我无法使用 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
4

1 回答 1

1

一旦你学会了使用 Heapshot Analysis ,定位有问题的分配/实现就很容易了。

Heapshot Analysis 允许您在执行期间拍摄快照,以检测一段时间内的增长,在许多情况下您当然可以将其与用户操作相关联。因此,例如,您可以将视图控制器推送到 iOS 中的导航堆栈上,然后退后一步,轻松确定这样做的增长情况。然后导航到导致增长的实现。

于 2012-11-06T08:38:13.320 回答