0

アプリケーションでメモリリークを見つけるために計測ツールを使用していますが、実際の問題がどこにあるかを特定できず、リークの計測ツールはこのクラスでリークを示しています。

-(IBAction) GoToNext:(id)sender{


    ////NSLog(@"iPad");
    NextClass *sampleView = [[[NextClass alloc] init] autorelease];
    sampleView.ImageName = @"Tutorial.png";
    sampleView.modalPresentationStyle = UIModalPresentationPageSheet;
    [sampleView setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
    [self presentModalViewController:sampleView animated:YES];
    sampleView.Title.text = @"On Christianity";
 }

NextClass.h ファイル

    #import <UIKit/UIKit.h>

@interface NextClass : UIViewController<UIScrollViewDelegate> {


    IBOutlet UINavigationBar* TopNavbar;
    IBOutlet UIScrollView *scrollView;
    IBOutlet UILabel *Title;
    NSString *ImageName;

    UIImageView *imageView;

}

@property(nonatomic,retain) UIImageView *imageView;
@property(nonatomic,retain) NSString *ImageName;
@property(nonatomic,retain) IBOutlet UILabel *Title;
@property(nonatomic,retain) IBOutlet UIScrollView *scrollView;
@property(nonatomic,retain) IBOutlet UINavigationBar* TopNavbar;
- (IBAction)dismissView:(id)sender;

@end

NextClass.m ファイル

    #import "NextClass.h"

    @implementation NextClass
    @synthesize TopNavbar,scrollView,Title,ImageName,imageView;
    CGPoint newCenter;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

    [super viewDidLoad];

    //Code for Managing Scrolling of Image.{#DR#-13/02/2012}
    [scrollView setBackgroundColor:[UIColor whiteColor]];
    [scrollView setCanCancelContentTouches:NO];
    scrollView.clipsToBounds = YES; 
    scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    UIImage *image=[UIImage imageNamed:ImageName];

    imageView = [[UIImageView alloc] init];

    [imageView setFrame:CGRectMake(0, 0, (image.size.width),image.size.height )];

    [imageView setImage:image];

    [scrollView addSubview:imageView];
    [scrollView setContentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height)];
    [scrollView setScrollEnabled:YES];

    for(UIView *subview in [scrollView subviews]) 
    {
        newCenter=scrollView.center;
        newCenter=CGPointMake(scrollView.center.x, imageView.frame.size.height/2);
        subview.center=newCenter;
    }

    [imageView release];


}

- (IBAction)dismissView:(id)sender {
    [self dismissModalViewControllerAnimated:YES];
}



- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.TopNavbar =nil;
    self.scrollView=nil;
    self.Title=nil;

}


- (void)dealloc {

    if (ImageName) {
        [ImageName release];
        ImageName=nil;
    }
    if (Title) {
        [Title release];
        Title=nil;
    }
    if (scrollView) {
        [scrollView release];
        scrollView=nil;
    }
    if (TopNavbar) {
        [TopNavbar release];
        TopNavbar=nil;
    }

    [super dealloc];
}

@end

次のリークを生成する Xcode のインストルメント ツールですが、コード内の実際の問題を見つけることができません。

Leaked Object   #   Address Size    Responsible Library Responsible Frame
GeneralBlock-48 7   < multiple >    336 libsystem_c.dylib   strdup
GeneralBlock-48     0x360c140   48  libsystem_c.dylib   strdup
GeneralBlock-48     0x360a060   48  libsystem_c.dylib   strdup
GeneralBlock-48     0x1b79e0    48  libsystem_c.dylib   strdup
GeneralBlock-48     0x1b79e0    48  libsystem_c.dylib   strdup
GeneralBlock-48     0x1ad910    48  libsystem_c.dylib   strdup
GeneralBlock-48     0x14e5a0    48  libsystem_c.dylib   strdup
GeneralBlock-48     0x14e5a0    48  libsystem_c.dylib   strdup

ありがとう

4

1 に答える 1

0

プロパティ「imageView」を解放することはありません。あなたの問題は、まさにARCが発明された理由です(そして、私たち全員が同様の問題を抱えています)-できるだけ早く切り替えて、決して振り返らないでください!)

于 2012-08-07T11:42:33.237 に答える