iPhone 内存泄漏

发布于 2024-12-10 12:20:32 字数 2216 浏览 0 评论 0原文

有这段代码 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];
    }

我在这些视图的转换中 我失去了记忆 我能做什么?

i have this code 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];
    }

in the transition of these views I'm losing memory
What I can do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦初启 2024-12-17 12:20:32

看来您不会返回 Vista 主体,而是分配一个全新的实例?
因此,vistaPrincipal 的第一个实例仍然存在,您无需忽略 vistaStrentgh,而是在此基础上创建一个新实例。您现在内存中有 2 个 vistaprincipal。
如果你再次进入 vista strentgh,你将分别拥有 2 个,然后是 3 个 - 它将无限增长。

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

Looks like you're not going back to vista principal, but allocating a fresh new intance of it?
So the first instance of vistaPrincipal is still there, and rather than dismissing vistaStrentgh, you create a new instance on top of that. You now have 2 vistaprincipal in memory.
If you go to vista strentgh again, you'll have 2 of each, then 3 - it'll gros infinitely.

In vista principal, rather than create a new vista principal, try calling [self.parentViewController dismissModalViewController]. If running on ios 5, make that [self.presentingViewController dismissModalViewController].

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文