gpt4 book ai didi

ios - 每次我进入这个 View 时内存都会增加,我不能在这段代码中使用 arc

转载 作者:行者123 更新时间:2023-11-29 13:25:30 25 4
gpt4 key购买 nike

每次我进入同一个 View 时,内存都会增加。即使我正在发布,也没有任何事情发生,而且由于较旧的应用程序问题,我无法使用 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 允许您在执行过程中拍摄快照,以检测一段时间内的增长情况,在许多情况下,您当然可以将其与用户操作相关联。因此,例如,您可以将 View Controller 推送到 iOS 中的导航堆栈,然后退后一步,轻松确定这样做的增长情况。然后导航到导致增长的实现。

关于ios - 每次我进入这个 View 时内存都会增加,我不能在这段代码中使用 arc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13247100/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com