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 的 Instruments Tool 产生以下泄漏,但我无法在我的代码中找出实际问题。

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 回答