而方向改变记忆正在增加

时间:2012-02-21 08:04:44

标签: objective-c ios ipad memory-management

对不起要问基本的问题。在我的viewcontroller中,当我旋转我的设备以防止我用@property和@synthesize修改我所有的IBOutlets时,内存正在上升,即使这样也没有工作,我的分配仍然会达到峰值我不知道是什么错误我在didrotate方法中做了我在下面提供了我的代码。这里我只修改我的IBOutlets的图像和框架。在下面提供的代码中是否有任何错误?

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
            if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){
                for(UIImageView *thumbImage in [tableSupportView subviews]){
                        UIImage *tempImage=[bookListDataSource bookAtIndex:thumbnilIndex].titleImage;
                        CGFloat thumbnilHeight=95*((float) tempImage.size.height/tempImage.size.width);
                        thumbImage.frame=CGRectMake(thumbnilIndex*125, (205-thumbnilHeight)/2, 95, thumbnilHeight);
                        thumbnilIndex++;
                }
                self.myoutlets.frame=cgrect(frames according to criteria);
                NSString *detailImagePath=[[NSBundle mainBundle] pathForResource:@"details_bg_nb" ofType:@"png"];
                UIImage *detailImage=[[UIImage alloc] initWithContentsOfFile:detailImagePath];
                UIColor *bookDetailViewColor=[[UIColor alloc] initWithPatternImage:detailImage];
                self.bookDetailView.backgroundColor=bookDetailViewColor;
                [bookDetailViewColor release];
                [detailImage release];
                NSString *listBGImagePath=[[NSBundle mainBundle] pathForResource:@"list_bg_nb" ofType:@"png"];
                UIImage *listBGImage=[[UIImage alloc] initWithContentsOfFile:listBGImagePath];
                UIColor *listHeaderContainerViewColor=[[UIColor alloc] initWithPatternImage:listBGImage];
                self.listHeaderContainerView.backgroundColor=listHeaderContainerViewColor;
                [listHeaderContainerViewColor release];
                [listBGImagePath release];

                NSString *listBandPath=[[NSBundle mainBundle] pathForResource:@"listband_potrait" ofType:@"png"];
                UIImage *listBand=[[UIImage alloc] initWithContentsOfFile:listBandPath];
                self.categoryBrandingImageView.image=listBand;
                [listBand release];
            }else {
                NSUInteger thumbnilIndex=0;
                NSUInteger numberOfBooks=[bookListDataSource numberOfBooks];
                for(UIImageView *thumbImage in [tableSupportView subviews]){
                        UIImage *tempImage=[bookListDataSource bookAtIndex:thumbnilIndex].titleImage;
                        CGFloat thumbnilHeight=85*((float) tempImage.size.height/tempImage.size.width);
                        thumbImage.frame=CGRectMake(thumbnilIndex*115, (CGRectGetHeight(tableSupportView.frame)-thumbnilHeight)/2.0, 85, thumbnilHeight);
                        thumbnilIndex++;
                    }
                }
            self.myoutlets.frame=cgrectmake(my custom frame);
                NSString *detailImagePath=[[NSBundle mainBundle] pathForResource:@"landscape_details_bg_nb" ofType:@"png"];
                UIImage *detailImage=[[UIImage alloc] initWithContentsOfFile:detailImagePath];
                UIColor *bookDetailViewColor=[[UIColor alloc] initWithPatternImage:detailImage];
                self.bookDetailView.backgroundColor=bookDetailViewColor;
                [bookDetailViewColor release];
                [detailImage release];

                NSString *listBGImagePath=[[NSBundle mainBundle] pathForResource:@"landscape_list_bg_nb" ofType:@"png"];
                UIImage *listBGImage=[[UIImage alloc] initWithContentsOfFile:listBGImagePath];
                UIColor *listHeaderContainerViewColor=[[UIColor alloc] initWithPatternImage:listBGImage];
                self.listHeaderContainerView.backgroundColor=listHeaderContainerViewColor;
                [listHeaderContainerViewColor release];
                [listBGImagePath release];

                NSString *listBandPath=[[NSBundle mainBundle] pathForResource:@"listband_landscape" ofType:@"png"];
                UIImage *listBand=[[UIImage alloc] initWithContentsOfFile:listBandPath];
                self.categoryBrandingImageView.image=listBand;
                [listBand release];
            }
            self.bookInformation.backgroundColor=[UIColor clearColor];
            self.bookDescrption.backgroundColor=[UIColor clearColor];
        }
    }

如果有任何泄漏,请提供解决方案。谢谢。

1 个答案:

答案 0 :(得分:1)

在这部分代码中你有一个错误 -

NSString *listBGImagePath=[[NSBundle mainBundle] pathForResource:@"landscape_list_bg_nb" ofType:@"png"];
UIImage *listBGImage=[[UIImage alloc] initWithContentsOfFile:listBGImagePath];
UIColor *listHeaderContainerViewColor=[[UIColor alloc] initWithPatternImage:listBGImage];
self.listHeaderContainerView.backgroundColor=listHeaderContainerViewColor;
[listHeaderContainerViewColor release];
[listBGImagePath release];

您必须发布listBGImage而不是listBGImagePath