iphone上的内存泄漏

时间:2011-10-18 20:09:50

标签: iphone objective-c ios cocoa-touch memory-management

我有这个代码vistaPrincipal.h

#import <UIKit/UIKit.h>

@interface vistaPrincipal : UIViewController

@property (retain, nonatomic) 
IBOutlet UIButton *botonHeros;


- (IBAction)botonHeros:(id)sender;

@end

vistaPrincipal.m


#import "vistaStrength.h"
#import "vistaPrincipal.h"



- (void)viewDidLoad

    {


     [super viewDidLoad];

    }

- (void)viewDidUnload
{

    [self setBotonHeros:nil];

    [super viewDidUnload];

}

- (IBAction)botonHeros:(id)sender {

    vistaStrength *vistaStr =[[vistaStrength alloc] initWithNibName:@"vistaStrength" bundle:nil];

    vistaStr.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:vistaStr animated:YES];

    [vistaStr release];


    }

vistaStrength.h


#import <UIKit/UIKit.h>

@interface vistaStrength : UIViewController


@property (retain, nonatomic) IBOutlet UIScrollView *scrollStrength;

@property (retain, nonatomic) IBOutlet UIButton *logoStrength;

@property (retain, nonatomic) IBOutlet UIButton *logoAgility;

@property (retain, nonatomic) IBOutlet UIButton *logoIntelligence;



- (IBAction)botonRegresar:(id)sender;
@end

vistaStrength.m

#import "vistaStrength.h"
#import "vistaPrincipal.h"


- (void)viewDidLoad{

    [super viewDidLoad];

    [scrollStrength setScrollEnabled:YES];
    [scrollStrength setContentSize:CGSizeMake(320,600)];

    }


- (void)viewDidUnload{
    [self setScrollStrength:nil];
    [self setLogoStrength:nil];
    [self setLogoAgility:nil];
    [self setLogoInteligence:nil];

    [super viewDidUnload];

    }

- (void)dealloc{
    [scrollStrength release];
    [logoStrength release];
    [logoAgility release];
    [logoInteligence release];


    [super dealloc];

    }

- (IBAction)botonRegresar:(id)sender{

    vistaPrincipal *primeraVista =[[vistaPrincipal alloc] initWithNibName:@"vistaPrincipal" bundle:nil];

    primeraVista.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:primeraVista animated:YES];


    [primeraVista release];
    }

在这些观点的转变中,我正在失去记忆 我能做什么?

1 个答案:

答案 0 :(得分:0)

看起来你不会回到vista校长那里,而是分配一个全新的内容吗? 所以vistaPrincipal的第一个实例仍然在那里,而不是解雇vistaStrentgh,你创建一个新的实例。你现在在记忆中有2个vistaprincipal。 如果你再次去vista strentgh,那么你将拥有2个,然后是3个 - 这将是无限的gros。

在vista主体中,尝试调用[self.parentViewController dismissModalViewController]而不是创建新的vista主体。如果在ios 5上运行,请[self.presentingViewController dismissModalViewController]。