我在视图控制器中找不到下面的代码。我正在修复内存问题。当我注释掉视图确实加载时,即使它需要大量的内存超过80 MB,我会做什么来解决它。我把所有变量都改为强到弱。
@interface bookNowViewController : UIViewController<GMSMapViewDelegate, UIGestureRecognizerDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionViewBook;
@property (weak, nonatomic) IBOutlet GMSMapView *mapLoc;
@property (weak, nonatomic) IBOutlet UILabel *distanceLbl;
@property (weak, nonatomic) IBOutlet UILabel *rateLbl;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionViewFacility;
@property (weak, nonatomic) IBOutlet UIView *contentView;
@property (weak, nonatomic) IBOutlet UIScrollView *mainScrollView;
@property (weak, nonatomic) IBOutlet UIImageView *animatedImages;//images with fading effect
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *facilityCollectionViewHight;
@property (weak, nonatomic) IBOutlet UILabel *noSportsAvailable;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *facilityLblHightConstant;
@property (weak, nonatomic) IBOutlet UILabel *stName;
@property (weak, nonatomic) IBOutlet UILabel *stAddress;
@property (weak, nonatomic) IBOutlet UIButton *btnI;
@property (weak, nonatomic) IBOutlet UIButton *moreBt;
@property (weak, nonatomic) IBOutlet UIButton *bookNowBt;
@property (weak, nonatomic) IBOutlet UILabel *spRating;
@property (weak, nonatomic) IBOutlet UIView *iNewView;
@property (weak, nonatomic) IBOutlet UILabel *infoLabel;
@property (weak, nonatomic) IBOutlet UILabel *lblIText;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UILabel *confirmationLblText;
和.m文件
@interface bookNowViewController (){
NSMutableArray *savedList, *stadiumAddress, *stadiumLatitude, *stadiumLongitude, *stadiumId, *stadiumImages, *stadiumPrice, *stadiumRating, *stadiumName, *savedImages, *listFacility, *facility, *vendorId, *vendorName, *sportsName;
NSString *post_id2, *postIndex2, *combineData2, *STName;
NSString *raterName, *ratingValue, *raterImage, *comment;
NSInteger myInt;
UIButton *button;
UILabel *navLabel;
NSString *stadium_Id;
NSMutableArray *imageView;// animation images array
UIView *hideView;
UITapGestureRecognizer *oneTap;
NSUInteger jk;
}
@end
并在viewdidload中
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self
selector:@selector(swapImage2) userInfo:nil repeats:YES];
[[NSUserDefaults standardUserDefaults] setObject: nil forKey: @"paymentTag"];
self.navigationController.navigationBar.hidden = NO;
stadium_Id = [[NSUserDefaults standardUserDefaults] valueForKey:@"stadium_Id"];
NSLog(@"%@", stadium_Id);
[ProgressHUD showSuccess:@"" Interaction:YES];
NSString *combined2 = stadium_Id;
NSArray* combineData = [[NSArray alloc]init];
combineData = [combined2 componentsSeparatedByString: @" "];
post_id2 = [combineData objectAtIndex:0];
[[NSUserDefaults standardUserDefaults] setObject: post_id2 forKey: @"stadiumid"];
NSLog(@"%@", post_id2);
postIndex2 = [ combineData objectAtIndex:1];
STName =[combineData objectAtIndex:2];
myInt = [postIndex2 integerValue];
NSLog(@"%ld", (long)myInt);
[self getStadiumDetail];
[self map2];
savedImages = [[NSUserDefaults standardUserDefaults] valueForKey:@"sportsImage"];
sportsName = [[NSUserDefaults standardUserDefaults] valueForKey:@"sportsName"];
if (savedImages.count<1) {
_infoLabel.hidden = NO;
_bookNowBt.hidden = YES;
}
else{
_infoLabel.hidden = YES;
}
[_collectionViewBook reloadData];
[_collectionViewFacility reloadData];
//////////tap gesture
oneTap.numberOfTapsRequired=1;
oneTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleSingleTap332)];
oneTap.delegate = self;
// [ProgressHUD showSuccess:@"" Interaction:YES];
self.btnI.layer.cornerRadius = self.btnI.frame.size.width/2;
[self.btnI.layer setBorderWidth:2.0];
[self.btnI.layer setBorderColor:[[UIColor grayColor] CGColor]];
_moreBt.layer.cornerRadius = 4.0f;
_bookNowBt.layer.cornerRadius = 4.0f;
_rateLbl.layer.borderColor = [UIColor lightGrayColor].CGColor;
_rateLbl.layer.borderWidth = 2.0f;
_rateLbl.layer.cornerRadius =_rateLbl.frame.size.width/2;
_rateLbl.clipsToBounds = YES;
_confirmationLblText.text = [[NSUserDefaults standardUserDefaults] valueForKey:@"savedPayText"];
答案 0 :(得分:0)
最后,你已经宣布了之前所有的图像。
每次pushtoViewController后都会为你创建的引用。
使用@autoreleasepool。
保留Outlets的弱引用,并为nil ** inviewWillDisapper分配任何强引用:。您可以将viewController模态地呈现为临时中断,以从用户那里获取重要信息。
我没有在应用程序中根据需要创建新的MKMapView,而是向我的AppDelegate添加了一个mkMapView属性,并且只在需要时才创建它。一旦创建它,它永远存在于AppDelegate中,我在所需的任何地方重用该单个实例。这确实有助于减少使用的内存量,因为我之前实例化了几个不同的MKMapView,并且两者都很快就在内存中燃烧。
不要使用-imageNamed我再说它不会使用imageNamed ever方法,因为它会缓存图像。使用它而不是-imageNamed :(在appDelegate上创建一个方法然后在任何你想要的地方调用它)
- (UIImage *)method4TakeImagesFromBundel:(NSString *)nameOfImage { NSString fileLocation = [[NSBundle mainBundle] pathForResource:nameOftheImage ofType:@&#34; png&#34;]; UIImage yourImage = [[UIImage alloc] initWithContentsOfFile:fileLocation]; 返回你的图像; }
NSData * imgData = UIImageJPEGRepresentation(rainyImage,0.1 / compressionQuality /);
- (UIImage *)imageWithImage:(UIImage *)image convertToSize:(CGSize)size { UIGraphicsBeginImageContext(大小); [image drawInRect:CGRectMake(0,0,size.width,size.height)]; UIImage * destImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext(); return destImage; }