iPhone 内存泄漏
有这段代码 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来您不会返回 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].